Search in sources :

Example 31 with VFSContainer

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;
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSItemSuffixFilter(org.olat.core.util.vfs.filters.VFSItemSuffixFilter) VFSContainer(org.olat.core.util.vfs.VFSContainer) ArrayList(java.util.ArrayList) VFSItem(org.olat.core.util.vfs.VFSItem) HashSet(java.util.HashSet) VFSLeafFilter(org.olat.core.util.vfs.filters.VFSLeafFilter)

Example 32 with VFSContainer

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

Example 33 with VFSContainer

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;
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSContainer(org.olat.core.util.vfs.VFSContainer) Identity(org.olat.core.id.Identity)

Example 34 with VFSContainer

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

Example 35 with VFSContainer

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();
}
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)

Aggregations

VFSContainer (org.olat.core.util.vfs.VFSContainer)962 VFSItem (org.olat.core.util.vfs.VFSItem)364 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)338 File (java.io.File)170 Test (org.junit.Test)136 OlatRootFolderImpl (org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl)86 Identity (org.olat.core.id.Identity)86 LocalFolderImpl (org.olat.core.util.vfs.LocalFolderImpl)76 RepositoryEntry (org.olat.repository.RepositoryEntry)76 IOException (java.io.IOException)74 InputStream (java.io.InputStream)64 ArrayList (java.util.ArrayList)64 Date (java.util.Date)60 URI (java.net.URI)56 MetaInfo (org.olat.core.commons.modules.bc.meta.MetaInfo)42 OutputStream (java.io.OutputStream)40 HttpResponse (org.apache.http.HttpResponse)38 MetaTagged (org.olat.core.commons.modules.bc.meta.tagged.MetaTagged)34 SubscriptionContext (org.olat.core.commons.services.notifications.SubscriptionContext)34 BlogFileResource (org.olat.fileresource.types.BlogFileResource)34