use of org.olat.core.util.vfs.VFSLeaf in project OpenOLAT by OpenOLAT.
the class VersionsFileManager method pruneVersionHistory.
private void pruneVersionHistory(VFSContainer container, long maxHistoryLength, ProgressDelegate progress, int count) {
List<VFSItem> children = container.getItems(new SystemItemFilter());
for (VFSItem child : children) {
if (child instanceof VFSContainer) {
if (progress != null)
progress.setActual(++count);
pruneVersionHistory((VFSContainer) child, maxHistoryLength, progress, count);
}
if (child instanceof VFSLeaf) {
VFSLeaf versionsLeaf = (VFSLeaf) child;
pruneVersionHistory(versionsLeaf, maxHistoryLength, progress);
}
}
}
use of org.olat.core.util.vfs.VFSLeaf in project OpenOLAT by OpenOLAT.
the class VersionsFileManager method getCanonicalVersionXmlFile.
/**
* Get the canonical path to the file's meta file.
*
* @param bcPath
* @return String
*/
private VFSLeaf getCanonicalVersionXmlFile(VFSItem item, boolean create) {
File f = getOriginFile(item);
if (!f.exists()) {
return null;
}
String relPath = getRelPath(item);
if (relPath == null) {
// cannot handle
return null;
}
File fVersion = new File(getRootVersionsFile(), relPath + ".xml");
File fParentVersion = fVersion.getParentFile();
if (!fParentVersion.exists() && create) {
fParentVersion.mkdirs();
}
if (fVersion.exists()) {
LocalFolderImpl localVersionContainer = new LocalFolderImpl(fParentVersion);
return (VFSLeaf) localVersionContainer.resolve(fVersion.getName());
} else if (create) {
LocalFolderImpl localVersionContainer = new LocalFolderImpl(fParentVersion);
VersionsFileImpl versions = new VersionsFileImpl();
versions.setVersioned(isVersioned(item));
versions.setRevisionNr(getNextRevisionNr(versions));
VFSLeaf fVersions = localVersionContainer.createChildLeaf(fVersion.getName());
XStreamHelper.writeObject(mystream, fVersions, versions);
return fVersions;
}
return null;
}
use of org.olat.core.util.vfs.VFSLeaf in project OpenOLAT by OpenOLAT.
the class VersionsFileManager method restore.
@Override
public boolean restore(VFSContainer container, VFSRevision revision) {
String filename = revision.getName();
VFSItem restoredItem = container.resolve(filename);
if (restoredItem == null) {
restoredItem = container.createChildLeaf(filename);
}
if (restoredItem instanceof VFSLeaf) {
VFSLeaf restoredLeaf = (VFSLeaf) restoredItem;
InputStream inStream = revision.getInputStream();
if (VFSManager.copyContent(inStream, restoredLeaf)) {
VFSLeaf versionFile = getCanonicalVersionXmlFile(restoredLeaf, true);
Versions versions = readVersions(restoredLeaf, versionFile);
if (versions instanceof VersionsFileImpl) {
versions.getRevisions().remove(revision);
((VersionsFileImpl) versions).setRevisionNr(getNextRevisionNr(versions));
}
XStreamHelper.writeObject(mystream, versionFile, versions);
return true;
}
}
return false;
}
use of org.olat.core.util.vfs.VFSLeaf in project OpenOLAT by OpenOLAT.
the class VersionsFileManager method delete.
@Override
public boolean delete(OrphanVersion orphan) {
VFSLeaf versionLeaf = orphan.getVersionsLeaf();
// already deleted
if (versionLeaf == null)
return true;
Versions versions = orphan.getVersions();
for (VFSRevision versionToDelete : versions.getRevisions()) {
RevisionFileImpl versionImpl = (RevisionFileImpl) versionToDelete;
versionImpl.setContainer(orphan.getVersionsLeaf().getParentContainer());
VFSLeaf fileToDelete = versionImpl.getFile();
if (fileToDelete != null) {
fileToDelete.delete();
}
}
versionLeaf.delete();
return true;
}
use of org.olat.core.util.vfs.VFSLeaf 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;
}
Aggregations