jdk/test/java/io/File/SymLinks.java
author jbachorik
Tue, 21 Jan 2014 13:04:55 +0100
changeset 22353 d09e3ff5fd63
parent 13568 ce5ab758aeb5
child 32649 2ee9017c7597
permissions -rw-r--r--
8032377: test/java/lang/management/ThreadMXBean/ThreadBlockedCount.java still fails intermittently Reviewed-by: dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3627
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
     1
/*
13568
ce5ab758aeb5 6931128: (spec) File attribute tests fail when run as root.
robm
parents: 9035
diff changeset
     2
 * Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved.
3627
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
     4
 *
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
     7
 * published by the Free Software Foundation.
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
     8
 *
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
    13
 * accompanied this code).
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
    14
 *
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3627
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3627
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3627
diff changeset
    21
 * questions.
3627
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
    22
 */
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
    23
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
    24
/* @test
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
    25
 * @bug 6595866
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
    26
 * @summary Test java.io.File operations with sym links
13568
ce5ab758aeb5 6931128: (spec) File attribute tests fail when run as root.
robm
parents: 9035
diff changeset
    27
 * @build SymLinks Util
ce5ab758aeb5 6931128: (spec) File attribute tests fail when run as root.
robm
parents: 9035
diff changeset
    28
 * @run main SymLinks
3627
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
    29
 */
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
    30
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
    31
import java.io.*;
8158
77d9c0f1c19f 7006126: (fs) Updates to file system API (1/2011)
alanb
parents: 5506
diff changeset
    32
import java.nio.file.*;
3627
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
    33
import java.nio.file.attribute.*;
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
    34
import static java.nio.file.LinkOption.*;
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
    35
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
    36
public class SymLinks {
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
    37
    final static PrintStream out = System.out;
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
    38
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
    39
    final static File top = new File(System.getProperty("test.dir", "."));
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
    40
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
    41
    // files used by the test
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
    42
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
    43
    final static File file              = new File(top, "foofile");
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
    44
    final static File link2file         = new File(top, "link2file");
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
    45
    final static File link2link2file    = new File(top, "link2link2file");
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
    46
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
    47
    final static File dir               = new File(top, "foodir");
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
    48
    final static File link2dir          = new File(top, "link2dir");
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
    49
    final static File link2link2dir     = new File(top, "link2link2dir");
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
    50
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
    51
    final static File link2nobody       = new File(top, "link2nobody");
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
    52
    final static File link2link2nobody  = new File(top, "link2link2nobody");
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
    53
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
    54
    /**
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
    55
     * Setup files, directories, and sym links used by test.
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
    56
     */
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
    57
    static void setup() throws IOException {
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
    58
        // link2link2file -> link2file -> foofile
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
    59
        FileOutputStream fos = new FileOutputStream(file);
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
    60
        try {
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
    61
            fos.write(new byte[16*1024]);
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
    62
        } finally {
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
    63
            fos.close();
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
    64
        }
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
    65
        mklink(link2file, file);
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
    66
        mklink(link2link2file, link2file);
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
    67
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
    68
        // link2link2dir -> link2dir -> dir
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
    69
        assertTrue(dir.mkdir());
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
    70
        mklink(link2dir, dir);
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
    71
        mklink(link2link2dir, link2dir);
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
    72
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
    73
        // link2link2nobody -> link2nobody -> <does-not-exist>
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
    74
        mklink(link2nobody, new File(top, "DoesNotExist"));
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
    75
        mklink(link2link2nobody, link2nobody);
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
    76
    }
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
    77
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
    78
    /**
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
    79
     * Remove files, directories, and sym links used by test.
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
    80
     */
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
    81
    static void cleanup() throws IOException {
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
    82
        if (file != null)
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
    83
            file.delete();
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
    84
        if (link2file != null)
8158
77d9c0f1c19f 7006126: (fs) Updates to file system API (1/2011)
alanb
parents: 5506
diff changeset
    85
            Files.deleteIfExists(link2file.toPath());
3627
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
    86
        if (link2link2file != null)
8158
77d9c0f1c19f 7006126: (fs) Updates to file system API (1/2011)
alanb
parents: 5506
diff changeset
    87
            Files.deleteIfExists(link2link2file.toPath());
3627
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
    88
        if (dir != null)
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
    89
            dir.delete();
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
    90
        if (link2dir != null)
8158
77d9c0f1c19f 7006126: (fs) Updates to file system API (1/2011)
alanb
parents: 5506
diff changeset
    91
            Files.deleteIfExists(link2dir.toPath());
3627
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
    92
        if (link2link2dir != null)
8158
77d9c0f1c19f 7006126: (fs) Updates to file system API (1/2011)
alanb
parents: 5506
diff changeset
    93
            Files.deleteIfExists(link2link2dir.toPath());
3627
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
    94
        if (link2nobody != null)
8158
77d9c0f1c19f 7006126: (fs) Updates to file system API (1/2011)
alanb
parents: 5506
diff changeset
    95
            Files.deleteIfExists(link2nobody.toPath());
3627
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
    96
        if (link2link2nobody != null)
8158
77d9c0f1c19f 7006126: (fs) Updates to file system API (1/2011)
alanb
parents: 5506
diff changeset
    97
            Files.deleteIfExists(link2link2nobody.toPath());
3627
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
    98
    }
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
    99
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   100
    /**
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   101
     * Creates a sym link source->target
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   102
     */
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   103
    static void mklink(File source, File target) throws IOException {
8158
77d9c0f1c19f 7006126: (fs) Updates to file system API (1/2011)
alanb
parents: 5506
diff changeset
   104
        Files.createSymbolicLink(source.toPath(), target.toPath());
3627
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   105
    }
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   106
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   107
    /**
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   108
     * Returns true if the "link" exists and is a sym link.
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   109
     */
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   110
    static boolean isSymLink(File link) {
8158
77d9c0f1c19f 7006126: (fs) Updates to file system API (1/2011)
alanb
parents: 5506
diff changeset
   111
         return Files.isSymbolicLink(link.toPath());
3627
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   112
    }
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   113
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   114
    /**
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   115
     * Returns the last modified time of a sym link.
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   116
     */
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   117
    static long lastModifiedOfSymLink(File link) throws IOException {
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   118
        BasicFileAttributes attrs =
8158
77d9c0f1c19f 7006126: (fs) Updates to file system API (1/2011)
alanb
parents: 5506
diff changeset
   119
            Files.readAttributes(link.toPath(), BasicFileAttributes.class, NOFOLLOW_LINKS);
3627
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   120
        assertTrue(attrs.isSymbolicLink());
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   121
        return attrs.lastModifiedTime().toMillis();
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   122
    }
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   123
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   124
    /**
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   125
     * Returns true if sym links are supported on the file system where
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   126
     * "dir" exists.
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   127
     */
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   128
    static boolean supportsSymLinks(File dir) {
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   129
        Path link = dir.toPath().resolve("link");
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   130
        Path target = dir.toPath().resolve("target");
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   131
        try {
8158
77d9c0f1c19f 7006126: (fs) Updates to file system API (1/2011)
alanb
parents: 5506
diff changeset
   132
            Files.createSymbolicLink(link, target);
77d9c0f1c19f 7006126: (fs) Updates to file system API (1/2011)
alanb
parents: 5506
diff changeset
   133
            Files.delete(link);
3627
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   134
            return true;
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   135
        } catch (UnsupportedOperationException x) {
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   136
            return false;
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   137
        } catch (IOException x) {
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   138
            return false;
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   139
        }
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   140
    }
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   141
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   142
    static void assertTrue(boolean v) {
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   143
        if (!v) throw new RuntimeException("Test failed");
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   144
    }
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   145
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   146
    static void assertFalse(boolean v) {
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   147
        assertTrue(!v);
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   148
    }
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   149
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   150
    static void header(String h) {
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   151
        out.println();
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   152
        out.println();
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   153
        out.println("-- " + h + " --");
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   154
    }
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   155
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   156
    /**
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   157
     * Tests go here.
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   158
     */
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   159
    static void go() throws IOException {
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   160
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   161
        // check setup
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   162
        assertTrue(file.isFile());
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   163
        assertTrue(isSymLink(link2file));
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   164
        assertTrue(isSymLink(link2link2file));
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   165
        assertTrue(dir.isDirectory());
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   166
        assertTrue(isSymLink(link2dir));
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   167
        assertTrue(isSymLink(link2link2dir));
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   168
        assertTrue(isSymLink(link2nobody));
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   169
        assertTrue(isSymLink(link2link2nobody));
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   170
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   171
        header("createNewFile");
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   172
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   173
        assertFalse(file.createNewFile());
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   174
        assertFalse(link2file.createNewFile());
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   175
        assertFalse(link2link2file.createNewFile());
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   176
        assertFalse(dir.createNewFile());
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   177
        assertFalse(link2dir.createNewFile());
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   178
        assertFalse(link2link2dir.createNewFile());
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   179
        assertFalse(link2nobody.createNewFile());
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   180
        assertFalse(link2link2nobody.createNewFile());
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   181
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   182
        header("mkdir");
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   183
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   184
        assertFalse(file.mkdir());
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   185
        assertFalse(link2file.mkdir());
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   186
        assertFalse(link2link2file.mkdir());
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   187
        assertFalse(dir.mkdir());
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   188
        assertFalse(link2dir.mkdir());
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   189
        assertFalse(link2link2dir.mkdir());
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   190
        assertFalse(link2nobody.mkdir());
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   191
        assertFalse(link2link2nobody.mkdir());
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   192
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   193
        header("delete");
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   194
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   195
        File link = new File(top, "mylink");
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   196
        try {
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   197
            mklink(link, file);
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   198
            assertTrue(link.delete());
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   199
            assertTrue(!isSymLink(link));
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   200
            assertTrue(file.exists());
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   201
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   202
            mklink(link, link2file);
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   203
            assertTrue(link.delete());
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   204
            assertTrue(!isSymLink(link));
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   205
            assertTrue(link2file.exists());
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   206
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   207
            mklink(link, dir);
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   208
            assertTrue(link.delete());
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   209
            assertTrue(!isSymLink(link));
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   210
            assertTrue(dir.exists());
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   211
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   212
            mklink(link, link2dir);
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   213
            assertTrue(link.delete());
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   214
            assertTrue(!isSymLink(link));
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   215
            assertTrue(link2dir.exists());
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   216
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   217
            mklink(link, link2nobody);
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   218
            assertTrue(link.delete());
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   219
            assertTrue(!isSymLink(link));
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   220
            assertTrue(isSymLink(link2nobody));
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   221
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   222
        } finally {
8158
77d9c0f1c19f 7006126: (fs) Updates to file system API (1/2011)
alanb
parents: 5506
diff changeset
   223
            Files.deleteIfExists(link.toPath());
3627
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   224
        }
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   225
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   226
        header("renameTo");
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   227
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   228
        File newlink = new File(top, "newlink");
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   229
        assertTrue(link2file.renameTo(newlink));
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   230
        try {
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   231
            assertTrue(file.exists());
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   232
            assertTrue(isSymLink(newlink));
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   233
            assertTrue(!isSymLink(link2file));
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   234
        } finally {
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   235
            newlink.renameTo(link2file);  // restore link
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   236
        }
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   237
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   238
        assertTrue(link2dir.renameTo(newlink));
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   239
        try {
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   240
            assertTrue(dir.exists());
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   241
            assertTrue(isSymLink(newlink));
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   242
            assertTrue(!isSymLink(link2dir));
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   243
        } finally {
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   244
            newlink.renameTo(link2dir);  // restore link
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   245
        }
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   246
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   247
        header("list");
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   248
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   249
        final String name = "entry";
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   250
        File entry = new File(dir, name);
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   251
        try {
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   252
            assertTrue(dir.list().length == 0);   // directory should be empty
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   253
            assertTrue(link2dir.list().length == 0);
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   254
            assertTrue(link2link2dir.list().length == 0);
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   255
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   256
            assertTrue(entry.createNewFile());
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   257
            assertTrue(dir.list().length == 1);
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   258
            assertTrue(dir.list()[0].equals(name));
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   259
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   260
            // access directory by following links
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   261
            assertTrue(link2dir.list().length == 1);
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   262
            assertTrue(link2dir.list()[0].equals(name));
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   263
            assertTrue(link2link2dir.list().length == 1);
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   264
            assertTrue(link2link2dir.list()[0].equals(name));
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   265
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   266
            // files that are not directories
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   267
            assertTrue(link2file.list() == null);
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   268
            assertTrue(link2nobody.list() == null);
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   269
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   270
        } finally {
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   271
            entry.delete();
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   272
        }
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   273
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   274
        header("isXXX");
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   275
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   276
        assertTrue(file.isFile());
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   277
        assertTrue(link2file.isFile());
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   278
        assertTrue(link2link2file.isFile());
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   279
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   280
        assertTrue(dir.isDirectory());
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   281
        assertTrue(link2dir.isDirectory());
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   282
        assertTrue(link2link2dir.isDirectory());
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   283
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   284
        // on Windows we test with the DOS hidden attribute set
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   285
        if (System.getProperty("os.name").startsWith("Windows")) {
8158
77d9c0f1c19f 7006126: (fs) Updates to file system API (1/2011)
alanb
parents: 5506
diff changeset
   286
            DosFileAttributeView view = Files
77d9c0f1c19f 7006126: (fs) Updates to file system API (1/2011)
alanb
parents: 5506
diff changeset
   287
                .getFileAttributeView(file.toPath(), DosFileAttributeView.class);
3627
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   288
            view.setHidden(true);
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   289
            try {
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   290
                assertTrue(file.isHidden());
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   291
                assertTrue(link2file.isHidden());
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   292
                assertTrue(link2link2file.isHidden());
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   293
            } finally {
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   294
                view.setHidden(false);
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   295
            }
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   296
            assertFalse(file.isHidden());
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   297
            assertFalse(link2file.isHidden());
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   298
            assertFalse(link2link2file.isHidden());
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   299
        }
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   300
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   301
        header("length");
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   302
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   303
        long len = file.length();
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   304
        assertTrue(len > 0L);
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   305
        // these tests should follow links
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   306
        assertTrue(link2file.length() == len);
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   307
        assertTrue(link2link2file.length() == len);
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   308
        assertTrue(link2nobody.length() == 0L);
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   309
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   310
        header("lastModified / setLastModified");
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   311
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   312
        // need time to diff between link and file
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   313
        long origLastModified = file.lastModified();
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   314
        assertTrue(origLastModified != 0L);
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   315
        try { Thread.sleep(2000); } catch (InterruptedException x) { }
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   316
        file.setLastModified(System.currentTimeMillis());
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   317
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   318
        long lastModified = file.lastModified();
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   319
        assertTrue(lastModified != origLastModified);
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   320
        assertTrue(lastModifiedOfSymLink(link2file) != lastModified);
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   321
        assertTrue(lastModifiedOfSymLink(link2link2file) != lastModified);
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   322
        assertTrue(link2file.lastModified() == lastModified);
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   323
        assertTrue(link2link2file.lastModified() == lastModified);
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   324
        assertTrue(link2nobody.lastModified() == 0L);
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   325
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   326
        origLastModified = dir.lastModified();
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   327
        assertTrue(origLastModified != 0L);
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   328
        dir.setLastModified(0L);
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   329
        assertTrue(dir.lastModified() == 0L);
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   330
        assertTrue(link2dir.lastModified() == 0L);
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   331
        assertTrue(link2link2dir.lastModified() == 0L);
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   332
        dir.setLastModified(origLastModified);
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   333
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   334
        header("setXXX / canXXX");
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   335
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   336
        assertTrue(file.canRead());
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   337
        assertTrue(file.canWrite());
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   338
        assertTrue(link2file.canRead());
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   339
        assertTrue(link2file.canWrite());
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   340
        assertTrue(link2link2file.canRead());
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   341
        assertTrue(link2link2file.canWrite());
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   342
13568
ce5ab758aeb5 6931128: (spec) File attribute tests fail when run as root.
robm
parents: 9035
diff changeset
   343
        if (!Util.isPrivileged() && file.setReadOnly()) {
3627
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   344
            assertFalse(file.canWrite());
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   345
            assertFalse(link2file.canWrite());
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   346
            assertFalse(link2link2file.canWrite());
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   347
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   348
            assertTrue(file.setWritable(true));             // make writable
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   349
            assertTrue(file.canWrite());
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   350
            assertTrue(link2file.canWrite());
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   351
            assertTrue(link2link2file.canWrite());
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   352
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   353
            assertTrue(link2file.setReadOnly());            // make read only
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   354
            assertFalse(file.canWrite());
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   355
            assertFalse(link2file.canWrite());
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   356
            assertFalse(link2link2file.canWrite());
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   357
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   358
            assertTrue(link2link2file.setWritable(true));   // make writable
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   359
            assertTrue(file.canWrite());
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   360
            assertTrue(link2file.canWrite());
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   361
            assertTrue(link2link2file.canWrite());
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   362
        }
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   363
    }
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   364
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   365
    public static void main(String[] args) throws IOException {
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   366
        if (supportsSymLinks(top)) {
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   367
            try {
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   368
                setup();
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   369
                go();
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   370
            } finally {
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   371
                cleanup();
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   372
            }
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   373
        }
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   374
    }
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   375
d0ad40d5adab 6595866: File does work with symbolic links (win,vista)
alanb
parents:
diff changeset
   376
}