1 /*
2 * Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package sun.nio.fs;
27
28 import java.nio.file.*;
29 import java.nio.file.attribute.*;
30 import java.io.*;
31 import java.net.URI;
32 import java.util.*;
33 import java.lang.ref.WeakReference;
34
35 import com.sun.nio.file.ExtendedWatchEventModifier;
36
37 import static sun.nio.fs.WindowsNativeDispatcher.*;
38 import static sun.nio.fs.WindowsConstants.*;
39
40 /**
41 * Windows implementation of Path
42 */
43
44 class WindowsPath implements Path {
45
46 // The maximum path that does not require long path prefix. On Windows
47 // the maximum path is 260 minus 1 (NUL) but for directories it is 260
48 // minus 12 minus 1 (to allow for the creation of a 8.3 file in the
49 // directory).
50 private static final int MAX_PATH = 247;
51
52 // Maximum extended-length path
53 private static final int MAX_LONG_PATH = 32000;
54
55 // FIXME - eliminate this reference to reduce space
56 private final WindowsFileSystem fs;
847 WatchEvent.Modifier... modifiers)
848 throws IOException
849 {
850 if (watcher == null)
851 throw new NullPointerException();
852 if (!(watcher instanceof WindowsWatchService))
853 throw new ProviderMismatchException();
854
855 // When a security manager is set then we need to make a defensive
856 // copy of the modifiers and check for the Windows specific FILE_TREE
857 // modifier. When the modifier is present then check that permission
858 // has been granted recursively.
859 SecurityManager sm = System.getSecurityManager();
860 if (sm != null) {
861 boolean watchSubtree = false;
862 final int ml = modifiers.length;
863 if (ml > 0) {
864 modifiers = Arrays.copyOf(modifiers, ml);
865 int i=0;
866 while (i < ml) {
867 if (modifiers[i++] == ExtendedWatchEventModifier.FILE_TREE) {
868 watchSubtree = true;
869 break;
870 }
871 }
872 }
873 String s = getPathForPermissionCheck();
874 sm.checkRead(s);
875 if (watchSubtree)
876 sm.checkRead(s + "\\-");
877 }
878
879 return ((WindowsWatchService)watcher).register(this, events, modifiers);
880 }
881 }
|
1 /*
2 * Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package sun.nio.fs;
27
28 import java.nio.file.*;
29 import java.nio.file.attribute.*;
30 import java.io.*;
31 import java.net.URI;
32 import java.util.*;
33 import java.lang.ref.WeakReference;
34
35 import static sun.nio.fs.WindowsNativeDispatcher.*;
36 import static sun.nio.fs.WindowsConstants.*;
37
38 /**
39 * Windows implementation of Path
40 */
41
42 class WindowsPath implements Path {
43
44 // The maximum path that does not require long path prefix. On Windows
45 // the maximum path is 260 minus 1 (NUL) but for directories it is 260
46 // minus 12 minus 1 (to allow for the creation of a 8.3 file in the
47 // directory).
48 private static final int MAX_PATH = 247;
49
50 // Maximum extended-length path
51 private static final int MAX_LONG_PATH = 32000;
52
53 // FIXME - eliminate this reference to reduce space
54 private final WindowsFileSystem fs;
845 WatchEvent.Modifier... modifiers)
846 throws IOException
847 {
848 if (watcher == null)
849 throw new NullPointerException();
850 if (!(watcher instanceof WindowsWatchService))
851 throw new ProviderMismatchException();
852
853 // When a security manager is set then we need to make a defensive
854 // copy of the modifiers and check for the Windows specific FILE_TREE
855 // modifier. When the modifier is present then check that permission
856 // has been granted recursively.
857 SecurityManager sm = System.getSecurityManager();
858 if (sm != null) {
859 boolean watchSubtree = false;
860 final int ml = modifiers.length;
861 if (ml > 0) {
862 modifiers = Arrays.copyOf(modifiers, ml);
863 int i=0;
864 while (i < ml) {
865 if (ExtendedOptions.FILE_TREE.matches(modifiers[i++])) {
866 watchSubtree = true;
867 break;
868 }
869 }
870 }
871 String s = getPathForPermissionCheck();
872 sm.checkRead(s);
873 if (watchSubtree)
874 sm.checkRead(s + "\\-");
875 }
876
877 return ((WindowsWatchService)watcher).register(this, events, modifiers);
878 }
879 }
|