private FileNaming rescanChild(
      final FileNaming folderName, final String childName, boolean ignoreCache) {
    final File folder = folderName.getFile();
    final File child = new File(folder, childName);
    final FileInfo fInfo = new FileInfo(child);

    FileNaming retval =
        (fInfo.isConvertibleToFileObject())
            ? NamingFactory.fromFile(folderName, child, ignoreCache)
            : null;
    if (retval != null) {
      addChild(folderName, retval);
    } else {
      FileName fChild =
          new FileName(folderName, child, null) {
            @Override
            public boolean isDirectory() {
              return false;
            }

            @Override
            public boolean isFile() {
              return false;
            }
          };

      removeChild(folderName, fChild);
    }

    return retval;
  }
 @Override
 public void run() {
   final File[] children = folder.listFiles();
   if (children != null) {
     newChildren = new LinkedHashSet<FileNaming>();
     for (int i = 0; i < children.length; i++) {
       final FileInfo fInfo = new FileInfo(children[i], 1);
       if (fInfo.isConvertibleToFileObject()) {
         FileNaming child = NamingFactory.fromFile(folderName, children[i], ignoreCache);
         newChildren.add(child);
       }
     }
   } else {
     folderExists = folder.exists();
     // #150009 - children == null -> folder does not exists, or an I/O error occurs
     // folder.listFiles() failed with I/O exception - do not remove children
   }
 }
Example #3
0
 public static int fileNamings() {
   return NamingFactory.getSize();
 }
  private FileNaming lookupChildInCache(
      final FileNaming folder, final String childName, boolean lookupExisting) {
    final File f = new File(folder.getFile(), childName);
    final Integer id = NamingFactory.createID(f);

    class FakeNaming implements FileNaming {
      public FileNaming lastEqual;

      public String getName() {
        return childName;
      }

      public FileNaming getParent() {
        return folder;
      }

      public boolean isRoot() {
        return false;
      }

      public File getFile() {
        return f;
      }

      public Integer getId() {
        return id;
      }

      public FileNaming rename(String name, ProvidedExtensions.IOHandler h) {
        // not implemented, as it will not be called
        throw new IllegalStateException();
      }

      @Override
      public boolean equals(Object obj) {
        if (hashCode() == obj.hashCode() && getName().equals(((FileNaming) obj).getName())) {
          assert lastEqual == null : "Just one can be there"; // NOI18N
          if (obj instanceof FileNaming) {
            lastEqual = (FileNaming) obj;
          }
          return true;
        }
        return false;
      }

      @Override
      public int hashCode() {
        return id.intValue();
      }

      public boolean isFile() {
        return this.getFile().isFile();
      }

      public boolean isDirectory() {
        return !isFile();
      }
    }
    FakeNaming fake = new FakeNaming();

    final Set<FileNaming> cache = (lookupExisting) ? getExisting(false) : getNotExisting(false);
    if (cache.contains(fake)) {
      assert fake.lastEqual != null : "If cache contains the object, we set lastEqual"; // NOI18N
      assert fake.lastEqual.getName().equals(childName)
          : "childName: " + childName + " equals: " + fake.lastEqual;
      return fake.lastEqual;
    } else {
      return null;
    }
  }