public static FileVersion createFileVersion(String path, FileVersion basedOnFileVersion) { FileVersion fileVersion = basedOnFileVersion.clone(); fileVersion.setPath(path); fileVersion.setStatus(FileStatus.CHANGED); fileVersion.setVersion(basedOnFileVersion.getVersion() + 1); return fileVersion; }
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; }
private FileVersion createFileVersion( String path, FileType type, FileVersion basedOnFileVersion) { if (basedOnFileVersion == null) { FileVersion fileVersion = new FileVersion(); fileVersion.setPath(path); fileVersion.setType(type); fileVersion.setVersion(1L); return fileVersion; } else { FileVersion fileVersion = basedOnFileVersion.clone(); fileVersion.setPath(path); fileVersion.setType(type); fileVersion.setVersion(basedOnFileVersion.getVersion() + 1); return fileVersion; } }
private void removeDeletedFiles( DatabaseVersion newDatabaseVersion, List<PartialFileHistory> fileHistoriesWithLastVersion) { logger.log(Level.FINER, "- Looking for deleted files ..."); for (PartialFileHistory fileHistory : fileHistoriesWithLastVersion) { // Ignore this file history if it has been updated in this database version before (file // probably renamed!) if (newDatabaseVersion.getFileHistory(fileHistory.getFileHistoryId()) != null) { continue; } // Check if file exists, remove if it doesn't FileVersion lastLocalVersion = fileHistory.getLastVersion(); File lastLocalVersionOnDisk = new File(config.getLocalDir() + File.separator + lastLocalVersion.getPath()); // Ignore this file history if the last version is marked "DELETED" if (lastLocalVersion.getStatus() == FileStatus.DELETED) { continue; } // Add this file history if a new file with this name has been added (file type change) PartialFileHistory newFileWithSameName = getFileHistoryByPathFromDatabaseVersion( newDatabaseVersion, fileHistory.getLastVersion().getPath()); // If file has VANISHED, mark as DELETED if (!FileUtil.exists(lastLocalVersionOnDisk) || newFileWithSameName != null) { PartialFileHistory deletedFileHistory = new PartialFileHistory(fileHistory.getFileHistoryId()); FileVersion deletedVersion = lastLocalVersion.clone(); deletedVersion.setStatus(FileStatus.DELETED); deletedVersion.setVersion(fileHistory.getLastVersion().getVersion() + 1); deletedVersion.setUpdated(new Date()); logger.log(Level.FINER, " + Deleted: Adding DELETED version: {0}", deletedVersion); logger.log(Level.FINER, " based on: {0}", lastLocalVersion); deletedFileHistory.addFileVersion(deletedVersion); newDatabaseVersion.addFileHistory(deletedFileHistory); } } }