Ejemplo n.º 1
0
 /**
  * Returns the current file cache.
  *
  * @param root root directory
  * @return id, or {@code null} if newer file cache exists
  * @throws InterruptedException interruption
  */
 ProjectCache cache(final IOFile root) throws InterruptedException {
   final ProjectCache pc = cache;
   if (pc == null) {
     // no file cache available: create and return new one
     cache = new ProjectCache();
     add(root, cache);
     cache.finish();
   } else {
     // wait until file cache is initialized
     while (!pc.valid()) {
       Thread.yield();
       // file cache was replaced with newer version
       if (pc != cache) throw new InterruptedException();
     }
   }
   // return existing file cache
   return cache;
 }
Ejemplo n.º 2
0
  /**
   * Recursively populates the cache.
   *
   * @param root root directory
   * @param pc file cache
   * @throws InterruptedException interruption
   */
  void add(final IOFile root, final ProjectCache pc) throws InterruptedException {
    // check if file cache was replaced or invalidated
    if (pc != cache) throw new InterruptedException();

    final IOFile[] files = root.children();
    for (final IOFile file : files) {
      if (file.name().equals(IO.IGNORESUFFIX)) return;
    }
    for (final IOFile file : files) {
      if (file.isDir()) {
        add(file, pc);
      } else {
        pc.add(file.path());
      }
    }
  }