use of org.olat.core.util.vfs.LocalFolderImpl 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.LocalFolderImpl in project OpenOLAT by OpenOLAT.
the class VersionsFileManager method getRootVersionsFile.
public File getRootVersionsFile() {
if (rootVersionsContainer == null) {
rootVersionFolder = new File(FolderConfig.getCanonicalVersionRoot());
if (!rootVersionFolder.exists()) {
rootVersionFolder.mkdirs();
}
rootVersionsContainer = new LocalFolderImpl(rootVersionFolder);
}
return rootVersionFolder;
}
use of org.olat.core.util.vfs.LocalFolderImpl in project OpenOLAT by OpenOLAT.
the class VersionsFileManager method getRootVersionsContainer.
public VFSContainer getRootVersionsContainer() {
if (rootVersionsContainer == null) {
rootVersionFolder = new File(FolderConfig.getCanonicalVersionRoot());
if (!rootVersionFolder.exists()) {
rootVersionFolder.mkdirs();
}
rootVersionsContainer = new LocalFolderImpl(rootVersionFolder);
}
return rootVersionsContainer;
}
use of org.olat.core.util.vfs.LocalFolderImpl 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();
}
use of org.olat.core.util.vfs.LocalFolderImpl in project OpenOLAT by OpenOLAT.
the class SimpleVersionConfig method versionEnabled.
public boolean versionEnabled(VFSContainer container) {
int versionsAllowed = getVersionAllowed();
if (versionsAllowed == 0) {
return false;
}
if (container instanceof NamedContainerImpl) {
container = ((NamedContainerImpl) container).getDelegate();
}
if (container instanceof MergeSource) {
container = ((MergeSource) container).getRootWriteContainer();
}
if (container instanceof LocalFolderImpl) {
try {
LocalFolderImpl folderImpl = (LocalFolderImpl) container;
String path = folderImpl.getBasefile().getCanonicalPath();
List<String> excludedRoots = getExcludedRoots();
for (String excludedRoot : excludedRoots) {
if (path.startsWith(excludedRoot)) {
return false;
}
}
String root = getCourseRoot();
if (path.startsWith(root)) {
for (String exclusion : EXCLUSIONS_IN_COURSE_PATH) {
if (path.indexOf(exclusion) > 0) {
return false;
}
}
}
return getVersionAllowed() != 0;
} catch (IOException e) {
// fail silently;
}
}
return false;
}
Aggregations