jdk/src/solaris/classes/sun/nio/fs/SolarisWatchService.java
changeset 8158 77d9c0f1c19f
parent 5506 202f599c92aa
child 9035 1255eb81cc2f
equal deleted inserted replaced
7988:d31b7cc371ef 8158:77d9c0f1c19f
   126      * WatchKey implementation
   126      * WatchKey implementation
   127      */
   127      */
   128     private class SolarisWatchKey extends AbstractWatchKey
   128     private class SolarisWatchKey extends AbstractWatchKey
   129         implements DirectoryNode
   129         implements DirectoryNode
   130     {
   130     {
   131         private final UnixPath dir;
       
   132         private final UnixFileKey fileKey;
   131         private final UnixFileKey fileKey;
   133 
   132 
   134         // pointer to native file_obj object
   133         // pointer to native file_obj object
   135         private final long object;
   134         private final long object;
   136 
   135 
   145                         UnixPath dir,
   144                         UnixPath dir,
   146                         UnixFileKey fileKey,
   145                         UnixFileKey fileKey,
   147                         long object,
   146                         long object,
   148                         Set<? extends WatchEvent.Kind<?>> events)
   147                         Set<? extends WatchEvent.Kind<?>> events)
   149         {
   148         {
   150             super(watcher);
   149             super(dir, watcher);
   151             this.dir = dir;
       
   152             this.fileKey = fileKey;
   150             this.fileKey = fileKey;
   153             this.object = object;
   151             this.object = object;
   154             this.events = events;
   152             this.events = events;
   155         }
   153         }
   156 
   154 
   157         UnixPath getFileRef() {
   155         UnixPath getDirectory() {
   158             return dir;
   156             return (UnixPath)watchable();
   159         }
   157         }
   160 
   158 
   161         UnixFileKey getFileKey() {
   159         UnixFileKey getFileKey() {
   162             return fileKey;
   160             return fileKey;
   163         }
   161         }
   485          * Process directory events. If directory is modified then re-scan
   483          * Process directory events. If directory is modified then re-scan
   486          * directory to register any new entries
   484          * directory to register any new entries
   487          */
   485          */
   488         void processDirectoryEvents(SolarisWatchKey key, int mask) {
   486         void processDirectoryEvents(SolarisWatchKey key, int mask) {
   489             if ((mask & (FILE_MODIFIED | FILE_ATTRIB)) != 0) {
   487             if ((mask & (FILE_MODIFIED | FILE_ATTRIB)) != 0) {
   490                 registerChildren(key.getFileRef(), key,
   488                 registerChildren(key.getDirectory(), key,
   491                     key.events().contains(StandardWatchEventKind.ENTRY_CREATE));
   489                     key.events().contains(StandardWatchEventKind.ENTRY_CREATE));
   492             }
   490             }
   493         }
   491         }
   494 
   492 
   495         /**
   493         /**
   522                 // workaround simple we don't check the st_ino so it isn't
   520                 // workaround simple we don't check the st_ino so it isn't
   523                 // effective when the file is replaced.
   521                 // effective when the file is replaced.
   524                 boolean removed = true;
   522                 boolean removed = true;
   525                 try {
   523                 try {
   526                     UnixFileAttributes
   524                     UnixFileAttributes
   527                         .get(key.getFileRef().resolve(node.name()), false);
   525                         .get(key.getDirectory().resolve(node.name()), false);
   528                     removed = false;
   526                     removed = false;
   529                 } catch (UnixException x) { }
   527                 } catch (UnixException x) { }
   530 
   528 
   531                 if (removed)
   529                 if (removed)
   532                     key.signalEvent(StandardWatchEventKind.ENTRY_DELETE, node.name());
   530                     key.signalEvent(StandardWatchEventKind.ENTRY_DELETE, node.name());
   552             if (parent.events().contains(StandardWatchEventKind.ENTRY_MODIFY))
   550             if (parent.events().contains(StandardWatchEventKind.ENTRY_MODIFY))
   553                 events |= (FILE_MODIFIED | FILE_ATTRIB);
   551                 events |= (FILE_MODIFIED | FILE_ATTRIB);
   554 
   552 
   555             DirectoryStream<Path> stream = null;
   553             DirectoryStream<Path> stream = null;
   556             try {
   554             try {
   557                 stream = dir.newDirectoryStream();
   555                 stream = Files.newDirectoryStream(dir);
   558             } catch (IOException x) {
   556             } catch (IOException x) {
   559                 // nothing we can do
   557                 // nothing we can do
   560                 return;
   558                 return;
   561             }
   559             }
   562             try {
   560             try {
   563                 for (Path entry: stream) {
   561                 for (Path entry: stream) {
   564                     Path name = entry.getName();
   562                     Path name = entry.getFileName();
   565 
   563 
   566                     // skip entry if already registered
   564                     // skip entry if already registered
   567                     if (parent.getChild(name) != null)
   565                     if (parent.getChild(name) != null)
   568                         continue;
   566                         continue;
   569 
   567 
   580                         // can't register so ignore for now.
   578                         // can't register so ignore for now.
   581                         continue;
   579                         continue;
   582                     }
   580                     }
   583 
   581 
   584                     // create node
   582                     // create node
   585                     EntryNode node = new EntryNode(object, entry.getName(), parent);
   583                     EntryNode node = new EntryNode(object, entry.getFileName(), parent);
   586                     // tell the parent about it
   584                     // tell the parent about it
   587                     parent.addChild(entry.getName(), node);
   585                     parent.addChild(entry.getFileName(), node);
   588                     object2Node.put(object, node);
   586                     object2Node.put(object, node);
   589                 }
   587                 }
   590             } catch (ConcurrentModificationException x) {
   588             } catch (ConcurrentModificationException x) {
   591                 // error during iteration which we ignore for now
   589                 // error during iteration which we ignore for now
   592             } finally {
   590             } finally {