Search in sources :

Example 6 with LockedFileFinder

use of org.eclipse.che.api.vfs.LockedFileFinder in project che by eclipse.

the class MemoryVirtualFile method delete.

@Override
public void delete(String lockToken) throws ForbiddenException, ServerException {
    checkExistence();
    boolean isFile = isFile();
    if (isRoot()) {
        throw new ForbiddenException("Unable delete root folder");
    }
    final Path myPath = getPath();
    final boolean folder = isFolder();
    if (folder) {
        final List<VirtualFile> lockedFiles = new LockedFileFinder(this).findLockedFiles();
        if (!lockedFiles.isEmpty()) {
            throw new ForbiddenException(String.format("Unable delete item '%s'. Child items '%s' are locked", getName(), lockedFiles));
        }
        for (VirtualFile virtualFile : getTreeAsList(this)) {
            ((MemoryVirtualFile) virtualFile).exists = false;
        }
    } else {
        if (fileIsLockedAndLockTokenIsInvalid(lockToken)) {
            throw new ForbiddenException(String.format("Unable delete item '%s'. Item is locked", getPath()));
        }
    }
    parent.children.remove(name);
    exists = false;
    parent = null;
    deleteFromSearcher(myPath, isFile);
}
Also used : Path(org.eclipse.che.api.vfs.Path) VirtualFile(org.eclipse.che.api.vfs.VirtualFile) ForbiddenException(org.eclipse.che.api.core.ForbiddenException) LockedFileFinder(org.eclipse.che.api.vfs.LockedFileFinder)

Aggregations

ForbiddenException (org.eclipse.che.api.core.ForbiddenException)6 LockedFileFinder (org.eclipse.che.api.vfs.LockedFileFinder)6 VirtualFile (org.eclipse.che.api.vfs.VirtualFile)6 Path (org.eclipse.che.api.vfs.Path)5 ConflictException (org.eclipse.che.api.core.ConflictException)4 File (java.io.File)3 ServerException (org.eclipse.che.api.core.ServerException)1