示例#1
0
    @Override
    public boolean onFileFilter(File file) {
      logger.log(Level.FINER, "- +File {0}", file);

      startFileProperties = fileVersionComparator.captureFileProperties(file, null, false);

      // Check if file has vanished
      if (!startFileProperties.exists() || startFileProperties.isLocked()) {
        logger.log(Level.FINER, "- /File: {0}", file);
        logger.log(
            Level.INFO,
            "   * NOT ADDING because file has VANISHED (exists = {0}) or is LOCKED (locked = {1}).",
            new Object[] {startFileProperties.exists(), startFileProperties.isLocked()});

        resetFileEnd();
        return false;
      }

      // Content
      if (startFileProperties.getType() == FileType.FILE) {
        logger.log(Level.FINER, "- +FileContent: {0}", file);
        fileContent = new FileContent();
      }

      return true;
    }
示例#2
0
    @Override
    public void onFileEnd(File file, byte[] rawFileChecksum) {
      // Get file attributes (get them while file exists)
      // Note: Do NOT move any File-methods (file.anything()) below the file.exists()-part,
      //       because the file could vanish!
      FileChecksum fileChecksum =
          (rawFileChecksum != null) ? new FileChecksum(rawFileChecksum) : null;
      endFileProperties = fileVersionComparator.captureFileProperties(file, fileChecksum, false);

      // Check if file has vanished
      boolean fileIsLocked = endFileProperties.isLocked();
      boolean fileVanished = !endFileProperties.exists();
      boolean fileHasChanged =
          startFileProperties.getSize() != endFileProperties.getSize()
              || startFileProperties.getLastModified() != endFileProperties.getLastModified();

      if (fileVanished || fileIsLocked || fileHasChanged) {
        logger.log(Level.FINER, "- /File: {0}", file);
        logger.log(
            Level.INFO,
            "   * NOT ADDING because file has VANISHED ("
                + !endFileProperties.exists()
                + "), is LOCKED ("
                + endFileProperties.isLocked()
                + "), or has CHANGED ("
                + fileHasChanged
                + ")");

        resetFileEnd();
        return;
      }

      // If it's still there, add it to the database
      addFileVersion(endFileProperties);

      // Reset
      resetFileEnd();
    }