1 /*
2 * Copyright (c) 2008, 2012, 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
215 for (WatchEvent.Kind<?> event: events) {
216 if (event == StandardWatchEventKinds.ENTRY_CREATE) {
217 mask |= IN_CREATE | IN_MOVED_TO;
218 continue;
219 }
220 if (event == StandardWatchEventKinds.ENTRY_DELETE) {
221 mask |= IN_DELETE | IN_MOVED_FROM;
222 continue;
223 }
224 if (event == StandardWatchEventKinds.ENTRY_MODIFY) {
225 mask |= IN_MODIFY | IN_ATTRIB;
226 continue;
227 }
228 }
229
230 // no modifiers supported at this time
231 if (modifiers.length > 0) {
232 for (WatchEvent.Modifier modifier: modifiers) {
233 if (modifier == null)
234 return new NullPointerException();
235 if (modifier instanceof com.sun.nio.file.SensitivityWatchEventModifier)
236 continue; // ignore
237 return new UnsupportedOperationException("Modifier not supported");
238 }
239 }
240
241 // check file is directory
242 UnixFileAttributes attrs = null;
243 try {
244 attrs = UnixFileAttributes.get(dir, true);
245 } catch (UnixException x) {
246 return x.asIOException(dir);
247 }
248 if (!attrs.isDirectory()) {
249 return new NotDirectoryException(dir.getPathForExceptionMessage());
250 }
251
252 // register with inotify (replaces existing mask if already registered)
253 int wd = -1;
254 try {
255 NativeBuffer buffer =
256 NativeBuffers.asNativeBuffer(dir.getByteArrayForSysCalls());
257 try {
258 wd = inotifyAddWatch(ifd, buffer.address(), mask);
259 } finally {
|
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
215 for (WatchEvent.Kind<?> event: events) {
216 if (event == StandardWatchEventKinds.ENTRY_CREATE) {
217 mask |= IN_CREATE | IN_MOVED_TO;
218 continue;
219 }
220 if (event == StandardWatchEventKinds.ENTRY_DELETE) {
221 mask |= IN_DELETE | IN_MOVED_FROM;
222 continue;
223 }
224 if (event == StandardWatchEventKinds.ENTRY_MODIFY) {
225 mask |= IN_MODIFY | IN_ATTRIB;
226 continue;
227 }
228 }
229
230 // no modifiers supported at this time
231 if (modifiers.length > 0) {
232 for (WatchEvent.Modifier modifier: modifiers) {
233 if (modifier == null)
234 return new NullPointerException();
235 if (!ExtendedOptions.SENSITIVITY_HIGH.matches(modifier) &&
236 !ExtendedOptions.SENSITIVITY_MEDIUM.matches(modifier) &&
237 !ExtendedOptions.SENSITIVITY_LOW.matches(modifier)) {
238 return new UnsupportedOperationException("Modifier not supported");
239 }
240 }
241 }
242
243 // check file is directory
244 UnixFileAttributes attrs = null;
245 try {
246 attrs = UnixFileAttributes.get(dir, true);
247 } catch (UnixException x) {
248 return x.asIOException(dir);
249 }
250 if (!attrs.isDirectory()) {
251 return new NotDirectoryException(dir.getPathForExceptionMessage());
252 }
253
254 // register with inotify (replaces existing mask if already registered)
255 int wd = -1;
256 try {
257 NativeBuffer buffer =
258 NativeBuffers.asNativeBuffer(dir.getByteArrayForSysCalls());
259 try {
260 wd = inotifyAddWatch(ifd, buffer.address(), mask);
261 } finally {
|