author | alanb |
Mon, 27 Jul 2009 18:44:42 +0100 | |
changeset 3326 | 31a5302fe6d4 |
parent 3065 | 452aaa2899fc |
child 4234 | d9720475ab15 |
permissions | -rw-r--r-- |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1 |
/* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
2 |
* Copyright 2008-2009 Sun Microsystems, Inc. All Rights Reserved. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
4 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
8 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
13 |
* accompanied this code). |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
14 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
18 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
19 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
20 |
* CA 95054 USA or visit www.sun.com if you need additional information or |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
21 |
* have any questions. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
22 |
*/ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
23 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
24 |
/* @test |
3326
31a5302fe6d4
6863864: (fs) Path.createSymbolicLink doesn't set directory flag when creating sym link to directory (win)
alanb
parents:
3065
diff
changeset
|
25 |
* @bug 4313887 6838333 6863864 |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
26 |
* @summary Unit test for java.nio.file.Path createSymbolicLink, |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
27 |
* readSymbolicLink, and createLink methods |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
28 |
* @library .. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
29 |
*/ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
30 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
31 |
import java.nio.file.*; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
32 |
import java.nio.file.attribute.*; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
33 |
import java.io.*; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
34 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
35 |
public class Links { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
36 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
37 |
static final boolean isWindows = |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
38 |
System.getProperty("os.name").startsWith("Windows"); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
39 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
40 |
static void assertTrue(boolean okay) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
41 |
if (!okay) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
42 |
throw new RuntimeException("Assertion failed"); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
43 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
44 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
45 |
/** |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
46 |
* Exercise createSymbolicLink and readLink methods |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
47 |
*/ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
48 |
static void testSymLinks(Path dir) throws IOException { |
3326
31a5302fe6d4
6863864: (fs) Path.createSymbolicLink doesn't set directory flag when creating sym link to directory (win)
alanb
parents:
3065
diff
changeset
|
49 |
final Path link = dir.resolve("link"); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
50 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
51 |
// Check if sym links are supported |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
52 |
try { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
53 |
link.createSymbolicLink(Paths.get("foo")); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
54 |
link.delete(); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
55 |
} catch (UnsupportedOperationException x) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
56 |
// sym links not supported |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
57 |
return; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
58 |
} catch (IOException x) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
59 |
// probably insufficient privileges to create sym links (Windows) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
60 |
return; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
61 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
62 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
63 |
// Test links to various targets |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
64 |
String[] windowsTargets = |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
65 |
{ "foo", "C:\\foo", "\\foo", "\\\\server\\share\\foo" }; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
66 |
String[] otherTargets = { "relative", "/absolute" }; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
67 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
68 |
String[] targets = (isWindows) ? windowsTargets : otherTargets; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
69 |
for (String s: targets) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
70 |
Path target = Paths.get(s); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
71 |
link.createSymbolicLink(target); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
72 |
try { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
73 |
assertTrue(link.readSymbolicLink().equals(target)); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
74 |
} finally { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
75 |
link.delete(); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
76 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
77 |
} |
3326
31a5302fe6d4
6863864: (fs) Path.createSymbolicLink doesn't set directory flag when creating sym link to directory (win)
alanb
parents:
3065
diff
changeset
|
78 |
|
31a5302fe6d4
6863864: (fs) Path.createSymbolicLink doesn't set directory flag when creating sym link to directory (win)
alanb
parents:
3065
diff
changeset
|
79 |
// Test links to directory |
31a5302fe6d4
6863864: (fs) Path.createSymbolicLink doesn't set directory flag when creating sym link to directory (win)
alanb
parents:
3065
diff
changeset
|
80 |
Path mydir = dir.resolve("mydir"); |
31a5302fe6d4
6863864: (fs) Path.createSymbolicLink doesn't set directory flag when creating sym link to directory (win)
alanb
parents:
3065
diff
changeset
|
81 |
Path myfile = mydir.resolve("myfile"); |
31a5302fe6d4
6863864: (fs) Path.createSymbolicLink doesn't set directory flag when creating sym link to directory (win)
alanb
parents:
3065
diff
changeset
|
82 |
try { |
31a5302fe6d4
6863864: (fs) Path.createSymbolicLink doesn't set directory flag when creating sym link to directory (win)
alanb
parents:
3065
diff
changeset
|
83 |
mydir.createDirectory(); |
31a5302fe6d4
6863864: (fs) Path.createSymbolicLink doesn't set directory flag when creating sym link to directory (win)
alanb
parents:
3065
diff
changeset
|
84 |
myfile.createFile(); |
31a5302fe6d4
6863864: (fs) Path.createSymbolicLink doesn't set directory flag when creating sym link to directory (win)
alanb
parents:
3065
diff
changeset
|
85 |
|
31a5302fe6d4
6863864: (fs) Path.createSymbolicLink doesn't set directory flag when creating sym link to directory (win)
alanb
parents:
3065
diff
changeset
|
86 |
// link -> "mydir" |
31a5302fe6d4
6863864: (fs) Path.createSymbolicLink doesn't set directory flag when creating sym link to directory (win)
alanb
parents:
3065
diff
changeset
|
87 |
link.createSymbolicLink(mydir.getName()); |
31a5302fe6d4
6863864: (fs) Path.createSymbolicLink doesn't set directory flag when creating sym link to directory (win)
alanb
parents:
3065
diff
changeset
|
88 |
assertTrue(link.readSymbolicLink().equals(mydir.getName())); |
31a5302fe6d4
6863864: (fs) Path.createSymbolicLink doesn't set directory flag when creating sym link to directory (win)
alanb
parents:
3065
diff
changeset
|
89 |
|
31a5302fe6d4
6863864: (fs) Path.createSymbolicLink doesn't set directory flag when creating sym link to directory (win)
alanb
parents:
3065
diff
changeset
|
90 |
// Test access to directory via link |
31a5302fe6d4
6863864: (fs) Path.createSymbolicLink doesn't set directory flag when creating sym link to directory (win)
alanb
parents:
3065
diff
changeset
|
91 |
DirectoryStream<Path> stream = link.newDirectoryStream(); |
31a5302fe6d4
6863864: (fs) Path.createSymbolicLink doesn't set directory flag when creating sym link to directory (win)
alanb
parents:
3065
diff
changeset
|
92 |
try { |
31a5302fe6d4
6863864: (fs) Path.createSymbolicLink doesn't set directory flag when creating sym link to directory (win)
alanb
parents:
3065
diff
changeset
|
93 |
boolean found = false; |
31a5302fe6d4
6863864: (fs) Path.createSymbolicLink doesn't set directory flag when creating sym link to directory (win)
alanb
parents:
3065
diff
changeset
|
94 |
for (Path entry: stream) { |
31a5302fe6d4
6863864: (fs) Path.createSymbolicLink doesn't set directory flag when creating sym link to directory (win)
alanb
parents:
3065
diff
changeset
|
95 |
if (entry.getName().equals(myfile.getName())) { |
31a5302fe6d4
6863864: (fs) Path.createSymbolicLink doesn't set directory flag when creating sym link to directory (win)
alanb
parents:
3065
diff
changeset
|
96 |
found = true; |
31a5302fe6d4
6863864: (fs) Path.createSymbolicLink doesn't set directory flag when creating sym link to directory (win)
alanb
parents:
3065
diff
changeset
|
97 |
break; |
31a5302fe6d4
6863864: (fs) Path.createSymbolicLink doesn't set directory flag when creating sym link to directory (win)
alanb
parents:
3065
diff
changeset
|
98 |
} |
31a5302fe6d4
6863864: (fs) Path.createSymbolicLink doesn't set directory flag when creating sym link to directory (win)
alanb
parents:
3065
diff
changeset
|
99 |
} |
31a5302fe6d4
6863864: (fs) Path.createSymbolicLink doesn't set directory flag when creating sym link to directory (win)
alanb
parents:
3065
diff
changeset
|
100 |
assertTrue(found); |
31a5302fe6d4
6863864: (fs) Path.createSymbolicLink doesn't set directory flag when creating sym link to directory (win)
alanb
parents:
3065
diff
changeset
|
101 |
} finally { |
31a5302fe6d4
6863864: (fs) Path.createSymbolicLink doesn't set directory flag when creating sym link to directory (win)
alanb
parents:
3065
diff
changeset
|
102 |
stream.close(); |
31a5302fe6d4
6863864: (fs) Path.createSymbolicLink doesn't set directory flag when creating sym link to directory (win)
alanb
parents:
3065
diff
changeset
|
103 |
} |
31a5302fe6d4
6863864: (fs) Path.createSymbolicLink doesn't set directory flag when creating sym link to directory (win)
alanb
parents:
3065
diff
changeset
|
104 |
|
31a5302fe6d4
6863864: (fs) Path.createSymbolicLink doesn't set directory flag when creating sym link to directory (win)
alanb
parents:
3065
diff
changeset
|
105 |
// Test link2 -> link -> mydir |
31a5302fe6d4
6863864: (fs) Path.createSymbolicLink doesn't set directory flag when creating sym link to directory (win)
alanb
parents:
3065
diff
changeset
|
106 |
final Path link2 = dir.resolve("link2"); |
31a5302fe6d4
6863864: (fs) Path.createSymbolicLink doesn't set directory flag when creating sym link to directory (win)
alanb
parents:
3065
diff
changeset
|
107 |
Path target2 = link.getName(); |
31a5302fe6d4
6863864: (fs) Path.createSymbolicLink doesn't set directory flag when creating sym link to directory (win)
alanb
parents:
3065
diff
changeset
|
108 |
link2.createSymbolicLink(target2); |
31a5302fe6d4
6863864: (fs) Path.createSymbolicLink doesn't set directory flag when creating sym link to directory (win)
alanb
parents:
3065
diff
changeset
|
109 |
try { |
31a5302fe6d4
6863864: (fs) Path.createSymbolicLink doesn't set directory flag when creating sym link to directory (win)
alanb
parents:
3065
diff
changeset
|
110 |
assertTrue(link2.readSymbolicLink().equals(target2)); |
31a5302fe6d4
6863864: (fs) Path.createSymbolicLink doesn't set directory flag when creating sym link to directory (win)
alanb
parents:
3065
diff
changeset
|
111 |
link2.newDirectoryStream().close(); |
31a5302fe6d4
6863864: (fs) Path.createSymbolicLink doesn't set directory flag when creating sym link to directory (win)
alanb
parents:
3065
diff
changeset
|
112 |
} finally { |
31a5302fe6d4
6863864: (fs) Path.createSymbolicLink doesn't set directory flag when creating sym link to directory (win)
alanb
parents:
3065
diff
changeset
|
113 |
link2.delete(); |
31a5302fe6d4
6863864: (fs) Path.createSymbolicLink doesn't set directory flag when creating sym link to directory (win)
alanb
parents:
3065
diff
changeset
|
114 |
} |
31a5302fe6d4
6863864: (fs) Path.createSymbolicLink doesn't set directory flag when creating sym link to directory (win)
alanb
parents:
3065
diff
changeset
|
115 |
|
31a5302fe6d4
6863864: (fs) Path.createSymbolicLink doesn't set directory flag when creating sym link to directory (win)
alanb
parents:
3065
diff
changeset
|
116 |
// Remove mydir and re-create link2 before re-creating mydir |
31a5302fe6d4
6863864: (fs) Path.createSymbolicLink doesn't set directory flag when creating sym link to directory (win)
alanb
parents:
3065
diff
changeset
|
117 |
// (This is a useful test on Windows to ensure that creating a |
31a5302fe6d4
6863864: (fs) Path.createSymbolicLink doesn't set directory flag when creating sym link to directory (win)
alanb
parents:
3065
diff
changeset
|
118 |
// sym link to a directory sym link creates the right type of link). |
31a5302fe6d4
6863864: (fs) Path.createSymbolicLink doesn't set directory flag when creating sym link to directory (win)
alanb
parents:
3065
diff
changeset
|
119 |
myfile.delete(); |
31a5302fe6d4
6863864: (fs) Path.createSymbolicLink doesn't set directory flag when creating sym link to directory (win)
alanb
parents:
3065
diff
changeset
|
120 |
mydir.delete(); |
31a5302fe6d4
6863864: (fs) Path.createSymbolicLink doesn't set directory flag when creating sym link to directory (win)
alanb
parents:
3065
diff
changeset
|
121 |
link2.createSymbolicLink(target2); |
31a5302fe6d4
6863864: (fs) Path.createSymbolicLink doesn't set directory flag when creating sym link to directory (win)
alanb
parents:
3065
diff
changeset
|
122 |
try { |
31a5302fe6d4
6863864: (fs) Path.createSymbolicLink doesn't set directory flag when creating sym link to directory (win)
alanb
parents:
3065
diff
changeset
|
123 |
assertTrue(link2.readSymbolicLink().equals(target2)); |
31a5302fe6d4
6863864: (fs) Path.createSymbolicLink doesn't set directory flag when creating sym link to directory (win)
alanb
parents:
3065
diff
changeset
|
124 |
mydir.createDirectory(); |
31a5302fe6d4
6863864: (fs) Path.createSymbolicLink doesn't set directory flag when creating sym link to directory (win)
alanb
parents:
3065
diff
changeset
|
125 |
link2.newDirectoryStream().close(); |
31a5302fe6d4
6863864: (fs) Path.createSymbolicLink doesn't set directory flag when creating sym link to directory (win)
alanb
parents:
3065
diff
changeset
|
126 |
} finally { |
31a5302fe6d4
6863864: (fs) Path.createSymbolicLink doesn't set directory flag when creating sym link to directory (win)
alanb
parents:
3065
diff
changeset
|
127 |
link2.delete(); |
31a5302fe6d4
6863864: (fs) Path.createSymbolicLink doesn't set directory flag when creating sym link to directory (win)
alanb
parents:
3065
diff
changeset
|
128 |
} |
31a5302fe6d4
6863864: (fs) Path.createSymbolicLink doesn't set directory flag when creating sym link to directory (win)
alanb
parents:
3065
diff
changeset
|
129 |
|
31a5302fe6d4
6863864: (fs) Path.createSymbolicLink doesn't set directory flag when creating sym link to directory (win)
alanb
parents:
3065
diff
changeset
|
130 |
} finally { |
31a5302fe6d4
6863864: (fs) Path.createSymbolicLink doesn't set directory flag when creating sym link to directory (win)
alanb
parents:
3065
diff
changeset
|
131 |
myfile.deleteIfExists(); |
31a5302fe6d4
6863864: (fs) Path.createSymbolicLink doesn't set directory flag when creating sym link to directory (win)
alanb
parents:
3065
diff
changeset
|
132 |
mydir.deleteIfExists(); |
31a5302fe6d4
6863864: (fs) Path.createSymbolicLink doesn't set directory flag when creating sym link to directory (win)
alanb
parents:
3065
diff
changeset
|
133 |
link.deleteIfExists(); |
31a5302fe6d4
6863864: (fs) Path.createSymbolicLink doesn't set directory flag when creating sym link to directory (win)
alanb
parents:
3065
diff
changeset
|
134 |
} |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
135 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
136 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
137 |
/** |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
138 |
* Exercise createLink method |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
139 |
*/ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
140 |
static void testHardLinks(Path dir) throws IOException { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
141 |
Path foo = dir.resolve("foo").createFile(); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
142 |
try { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
143 |
Path bar; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
144 |
try { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
145 |
bar = dir.resolve("bar").createLink(foo); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
146 |
} catch (UnsupportedOperationException x) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
147 |
return; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
148 |
} catch (IOException x) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
149 |
// probably insufficient privileges (Windows) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
150 |
return; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
151 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
152 |
try { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
153 |
Object key1 = Attributes |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
154 |
.readBasicFileAttributes(foo).fileKey(); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
155 |
Object key2 = Attributes |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
156 |
.readBasicFileAttributes(bar).fileKey(); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
157 |
assertTrue((key1 == null) || (key1.equals(key2))); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
158 |
} finally { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
159 |
bar.delete(); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
160 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
161 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
162 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
163 |
} finally { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
164 |
foo.delete(); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
165 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
166 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
167 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
168 |
public static void main(String[] args) throws IOException { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
169 |
Path dir = TestUtil.createTemporaryDirectory(); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
170 |
try { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
171 |
testSymLinks(dir); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
172 |
testHardLinks(dir); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
173 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
174 |
// repeat tests on Windows with long path |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
175 |
if (isWindows) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
176 |
Path dirWithLongPath = null; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
177 |
try { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
178 |
dirWithLongPath = TestUtil.createDirectoryWithLongPath(dir); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
179 |
} catch (IOException x) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
180 |
System.out.println("Unable to create long path: " + x); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
181 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
182 |
if (dirWithLongPath != null) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
183 |
System.out.println(""); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
184 |
System.out.println("** REPEAT TESTS WITH LONG PATH **"); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
185 |
testSymLinks(dirWithLongPath); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
186 |
testHardLinks(dirWithLongPath); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
187 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
188 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
189 |
} finally { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
190 |
TestUtil.removeAll(dir); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
191 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
192 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
193 |
} |