return new PartialFileHistory(lastFileHistory.getFileHistoryId());
}
}
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());
if (fileVersion.getType() == FileType.FOLDER) {
fileVersion.setPosixPermissions(DEFAULT_POSIX_PERMISSIONS_FOLDER);
}
else {
fileVersion.setPosixPermissions(DEFAULT_POSIX_PERMISSIONS_FILE);
}
}
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;
}