Search in sources :

Example 6 with LocalFolderImpl

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;
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) File(java.io.File) LocalFolderImpl(org.olat.core.util.vfs.LocalFolderImpl)

Example 7 with LocalFolderImpl

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;
}
Also used : File(java.io.File) LocalFolderImpl(org.olat.core.util.vfs.LocalFolderImpl)

Example 8 with LocalFolderImpl

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;
}
Also used : File(java.io.File) LocalFolderImpl(org.olat.core.util.vfs.LocalFolderImpl)

Example 9 with LocalFolderImpl

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();
}
Also used : VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem) File(java.io.File) LocalFolderImpl(org.olat.core.util.vfs.LocalFolderImpl)

Example 10 with LocalFolderImpl

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;
}
Also used : MergeSource(org.olat.core.util.vfs.MergeSource) IOException(java.io.IOException) NamedContainerImpl(org.olat.core.util.vfs.NamedContainerImpl) LocalFolderImpl(org.olat.core.util.vfs.LocalFolderImpl)

Aggregations

LocalFolderImpl (org.olat.core.util.vfs.LocalFolderImpl)122 File (java.io.File)82 VFSContainer (org.olat.core.util.vfs.VFSContainer)76 VFSItem (org.olat.core.util.vfs.VFSItem)38 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)30 ArrayList (java.util.ArrayList)14 IOException (java.io.IOException)10 Document (org.dom4j.Document)10 RepositoryEntry (org.olat.repository.RepositoryEntry)10 CloseableModalController (org.olat.core.gui.control.generic.closablewrapper.CloseableModalController)8 DeliveryOptions (org.olat.core.gui.control.generic.iframe.DeliveryOptions)8 OLATResource (org.olat.resource.OLATResource)8 Date (java.util.Date)6 Document (org.apache.lucene.document.Document)6 Element (org.dom4j.Element)6 OlatRootFolderImpl (org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl)6 LocalFileImpl (org.olat.core.util.vfs.LocalFileImpl)6 CourseEnvironment (org.olat.course.run.environment.CourseEnvironment)6 CPPackageConfig (org.olat.ims.cp.ui.CPPackageConfig)6 SearchResourceContext (org.olat.search.service.SearchResourceContext)6