use of org.olat.core.util.vfs.VFSContainer in project OpenOLAT by OpenOLAT.
the class VersionsFileManager method getDeletedFiles.
@Override
public List<Versions> getDeletedFiles(VFSContainer container) {
List<Versions> deletedRevisions = new ArrayList<Versions>();
VFSContainer versionContainer = getCanonicalVersionFolder(container, false);
if (versionContainer != null) {
Set<String> currentNames = new HashSet<String>();
for (VFSItem item : container.getItems(new VFSLeafFilter())) {
currentNames.add(item.getName() + ".xml");
}
List<VFSItem> versionItems = versionContainer.getItems(new VFSItemSuffixFilter(new String[] { "xml" }));
for (VFSItem versionItem : versionItems) {
String name = versionItem.getName();
if (versionItem instanceof VFSLeaf && !currentNames.contains(name) && isVersionsXmlFile((VFSLeaf) versionItem)) {
Versions versions = readVersions(null, (VFSLeaf) versionItem);
if (versions != null) {
List<VFSRevision> revisions = versions.getRevisions();
if (!revisions.isEmpty()) {
deletedRevisions.add(versions);
}
}
}
}
}
return deletedRevisions;
}
use of org.olat.core.util.vfs.VFSContainer in project OpenOLAT by OpenOLAT.
the class VersionsFileManager method readVersions.
private Versions readVersions(VFSLeaf leaf, VFSLeaf fVersions) {
if (fVersions == null) {
return new NotVersioned();
}
try {
VFSContainer fVersionContainer = fVersions.getParentContainer();
VersionsFileImpl versions = (VersionsFileImpl) XStreamHelper.readObject(mystream, fVersions);
versions.setVersionFile(fVersions);
versions.setCurrentVersion((Versionable) leaf);
if (versions.getRevisionNr() == null || versions.getRevisionNr().length() == 0) {
versions.setRevisionNr(getNextRevisionNr(versions));
}
for (VFSRevision revision : versions.getRevisions()) {
RevisionFileImpl revisionImpl = (RevisionFileImpl) revision;
revisionImpl.setContainer(fVersionContainer);
}
return versions;
} catch (Exception e) {
log.warn("This file is not a versions XML file: " + fVersions, e);
fVersions.delete();
VersionsFileImpl versions = new VersionsFileImpl();
versions.setCurrentVersion((Versionable) leaf);
versions.setVersioned(isVersioned(leaf));
versions.setRevisionNr(getNextRevisionNr(versions));
log.warn("Deleted corrupt version XML file and created new version XML file: " + versions);
// manually. This is not a perfect solution, but at least the user does not get an RS
return versions;
}
}
use of org.olat.core.util.vfs.VFSContainer in project OpenOLAT by OpenOLAT.
the class VersionsFileManager method delete.
@Override
public boolean delete(VFSItem item, boolean force) {
if (item instanceof VFSContainer) {
if (force) {
VFSContainer container = (VFSContainer) item;
VFSContainer versionContainer = getCanonicalVersionFolder(container, false);
if (versionContainer == null) {
return true;
}
return VFSConstants.YES.equals(versionContainer.delete());
}
return true;
} else if (item instanceof VFSLeaf && item instanceof Versionable) {
VFSLeaf leaf = (VFSLeaf) item;
if (force || isTemporaryFile(leaf)) {
cleanUp(leaf);
} else {
Identity identity = ThreadLocalUserActivityLogger.getLoggedIdentity();
addToRevisions((Versionable) leaf, identity, null);
}
}
return false;
}
use of org.olat.core.util.vfs.VFSContainer in project OpenOLAT by OpenOLAT.
the class VersionsFileManager method rename.
@Override
public boolean rename(VFSItem item, String newname) {
if (item instanceof VFSLeaf) {
VFSLeaf currentFile = (VFSLeaf) item;
VFSLeaf versionFile = getCanonicalVersionXmlFile(currentFile, true);
// infinite loop if rename is own versions file
return VFSConstants.YES.equals(versionFile.rename(newname + ".xml"));
} else if (item instanceof VFSContainer) {
VFSContainer container = (VFSContainer) item;
VFSContainer versionContainer = getCanonicalVersionFolder(container, false);
if (versionContainer == null) {
return true;
}
return VFSConstants.YES.equals(versionContainer.rename(newname));
}
return false;
}
use of org.olat.core.util.vfs.VFSContainer in project OpenOLAT by OpenOLAT.
the class VersionsFileManager method pruneHistory.
@Override
public void pruneHistory(long maxHistoryLength, ProgressDelegate progress) {
VFSContainer versionsContainer = getRootVersionsContainer();
if (!versionsContainer.exists()) {
return;
}
// delete folder without versioning first
int count = 0;
String[] excludedRootFolders = new String[] { "tmp", "scorm", "forum", "portfolio" };
for (String excludedRootFolder : excludedRootFolders) {
VFSItem excludedContainer = versionsContainer.resolve(excludedRootFolder);
if (excludedContainer instanceof LocalFolderImpl) {
File excludedFile = ((LocalFolderImpl) excludedContainer).getBasefile();
FileUtils.deleteQuietly(excludedFile);
if (progress != null)
progress.setInfo(excludedContainer.getName());
}
if (progress != null)
progress.setActual(++count);
}
if (maxHistoryLength < 0) {
// nothing to do
} else if (maxHistoryLength == 0 && versionsContainer instanceof LocalFolderImpl) {
// delete all the stuff
FileUtils.deleteQuietly(((LocalFolderImpl) versionsContainer).getBasefile());
} else {
pruneVersionHistory(versionsContainer, maxHistoryLength, progress, count);
}
if (progress != null)
progress.finished();
}
Aggregations