public static FileVersion createFileVersion(String path) {
    FileVersion fileVersion = new FileVersion();

    fileVersion.setChecksum(new FileChecksum(TestFileUtil.createRandomArray(20)));
    fileVersion.setLastModified(new Date());
    fileVersion.setPath(path);
    fileVersion.setStatus(FileStatus.NEW);
    fileVersion.setType(FileType.FILE);
    fileVersion.setUpdated(new Date());
    fileVersion.setVersion(1L);

    return fileVersion;
  }
Beispiel #2
0
    private FileVersion createNewFileVersion(
        FileVersion lastFileVersion, FileProperties fileProperties) {
      FileVersion fileVersion = null;

      // Version
      if (lastFileVersion == null) {
        fileVersion = new FileVersion();
        fileVersion.setVersion(1L);
        fileVersion.setStatus(FileStatus.NEW);
      } else {
        fileVersion = lastFileVersion.clone();
        fileVersion.setVersion(lastFileVersion.getVersion() + 1);
      }

      // Simple attributes
      fileVersion.setPath(fileProperties.getRelativePath());
      fileVersion.setLinkTarget(fileProperties.getLinkTarget());
      fileVersion.setType(fileProperties.getType());
      fileVersion.setSize(fileProperties.getSize());
      fileVersion.setChecksum(fileProperties.getChecksum());
      fileVersion.setLastModified(new Date(fileProperties.getLastModified()));
      fileVersion.setUpdated(new Date());

      // Permissions
      if (EnvironmentUtil.isWindows()) {
        fileVersion.setDosAttributes(fileProperties.getDosAttributes());
        fileVersion.setPosixPermissions(DEFAULT_POSIX_PERMISSIONS);
      } else if (EnvironmentUtil.isUnixLikeOperatingSystem()) {
        fileVersion.setPosixPermissions(fileProperties.getPosixPermissions());
        fileVersion.setDosAttributes(DEFAULT_DOS_ATTRIBUTES);
      }

      // Status
      if (lastFileVersion != null) {
        if (fileVersion.getType() == FileType.FILE
            && FileChecksum.fileChecksumEquals(
                fileVersion.getChecksum(), lastFileVersion.getChecksum())) {
          fileVersion.setStatus(FileStatus.CHANGED);
        } else if (!fileVersion.getPath().equals(lastFileVersion.getPath())) {
          fileVersion.setStatus(FileStatus.RENAMED);
        } else {
          fileVersion.setStatus(FileStatus.CHANGED);
        }
      }

      return fileVersion;
    }