Search in sources :

Example 1 with NotFileCacheException

use of diskCacheV111.util.NotFileCacheException in project dcache by dCache.

the class ChimeraNameSpaceProvider method removeLabel.

/**
 * @param subject The user making the request. Remove a label from a file.
 * @param path    The file from which the label  is deleted.
 * @param label   The name of the label to remove.
 * @throws FileNotFoundCacheException     if the path does not exist.
 * @throws PermissionDeniedCacheException if the user is not allowed to remove the label.
 * @throws CacheException                 a generic failure in removing the labe.
 */
public void removeLabel(Subject subject, FsPath path, String label) throws CacheException {
    try {
        ExtendedInode target = pathToInode(subject, path.toString());
        if (!Subjects.isRoot(subject)) {
            FileAttributes attributes = getFileAttributesForPermissionHandler(target);
            if (target.isDirectory()) {
                throw new NotFileCacheException("Directory object cannot have a label.");
            } else {
                if (_permissionHandler.canWriteFile(subject, attributes) != ACCESS_ALLOWED) {
                    throw new PermissionDeniedCacheException("Access denied");
                }
            }
        }
        _fs.removeLabel(target, label);
    } catch (FileNotFoundChimeraFsException e) {
        throw new FileNotFoundCacheException("No such file " + path);
    } catch (ChimeraFsException e) {
        throw new CacheException("Failed to remove the label: " + Exceptions.messageOrClassName(e), e);
    }
}
Also used : FileNotFoundChimeraFsException(org.dcache.chimera.FileNotFoundChimeraFsException) NotFileCacheException(diskCacheV111.util.NotFileCacheException) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) ChimeraFsException(org.dcache.chimera.ChimeraFsException) DirNotEmptyChimeraFsException(org.dcache.chimera.DirNotEmptyChimeraFsException) FileExistsChimeraFsException(org.dcache.chimera.FileExistsChimeraFsException) FileNotFoundChimeraFsException(org.dcache.chimera.FileNotFoundChimeraFsException) FileIsNewCacheException(diskCacheV111.util.FileIsNewCacheException) FileExistsCacheException(diskCacheV111.util.FileExistsCacheException) LockedCacheException(diskCacheV111.util.LockedCacheException) AttributeExistsCacheException(diskCacheV111.util.AttributeExistsCacheException) NotDirCacheException(diskCacheV111.util.NotDirCacheException) InvalidMessageCacheException(diskCacheV111.util.InvalidMessageCacheException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) NotFileCacheException(diskCacheV111.util.NotFileCacheException) CacheException(diskCacheV111.util.CacheException) NoAttributeCacheException(diskCacheV111.util.NoAttributeCacheException) FileCorruptedCacheException(diskCacheV111.util.FileCorruptedCacheException) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) FileAttributes(org.dcache.vehicles.FileAttributes)

Example 2 with NotFileCacheException

use of diskCacheV111.util.NotFileCacheException in project dcache by dCache.

the class ChimeraNameSpaceProvider method checkAllowed.

private void checkAllowed(Set<FileType> allowed, ExtendedInode inode) throws ChimeraFsException, NotDirCacheException, NotFileCacheException {
    FileType type = inode.getFileType();
    if (!allowed.contains(type)) {
        StringBuilder sb = new StringBuilder("Path exists and has type ").append(type).append(", which is not ");
        if (allowed.size() == 1) {
            FileType allowedType = allowed.iterator().next();
            sb.append(allowedType);
        } else {
            String description = allowed.stream().map(FileType::toString).collect(Collectors.joining(", ", "{", "}"));
            sb.append("one of ").append(description);
        }
        if (allowed.contains(FileType.DIR)) {
            throw new NotDirCacheException(sb.toString());
        } else {
            throw new NotFileCacheException(sb.toString());
        }
    }
}
Also used : NotFileCacheException(diskCacheV111.util.NotFileCacheException) FileType(org.dcache.namespace.FileType) NotDirCacheException(diskCacheV111.util.NotDirCacheException)

Example 3 with NotFileCacheException

use of diskCacheV111.util.NotFileCacheException in project dcache by dCache.

the class ChimeraNameSpaceProvider method checkIsTemporaryDirectory.

protected void checkIsTemporaryDirectory(FsPath temporaryPath, FsPath temporaryDir) throws NotFileCacheException, InvalidMessageCacheException {
    checkState(_uploadDirectory != null, "Upload directory is not configured.");
    FsPath temporaryDirContainer = getParentOfFile(temporaryDir);
    if (_uploadDirectory.startsWith("/")) {
        if (!temporaryDirContainer.hasPrefix(FsPath.create(_uploadDirectory))) {
            throw new InvalidMessageCacheException(temporaryPath + " is not part of the " + _uploadDirectory + " tree.");
        }
    } else {
        if (!temporaryDirContainer.contains(_uploadDirectory)) {
            throw new InvalidMessageCacheException(temporaryPath + " is not part of the " + _uploadDirectory + " tree.");
        }
    }
    if (temporaryDir.isRoot()) {
        throw new InvalidMessageCacheException("A temporary upload path cannot be in the root directory.");
    }
}
Also used : InvalidMessageCacheException(diskCacheV111.util.InvalidMessageCacheException) FsPath(diskCacheV111.util.FsPath)

Example 4 with NotFileCacheException

use of diskCacheV111.util.NotFileCacheException in project dcache by dCache.

the class Transfer method readNameSpaceEntryAsync.

private ListenableFuture<Void> readNameSpaceEntryAsync(boolean allowWrite, long timeout) {
    Set<FileAttribute> attr = EnumSet.of(PNFSID, TYPE, STORAGEINFO, SIZE);
    attr.addAll(_additionalAttributes);
    attr.addAll(PoolMgrSelectReadPoolMsg.getRequiredAttributes());
    Set<AccessMask> mask;
    if (allowWrite) {
        mask = EnumSet.of(AccessMask.READ_DATA, AccessMask.WRITE_DATA);
    } else {
        mask = EnumSet.of(AccessMask.READ_DATA);
    }
    PnfsId pnfsId = getPnfsId();
    PnfsGetFileAttributes request;
    if (pnfsId != null) {
        request = new PnfsGetFileAttributes(pnfsId, attr);
        if (_path != null) {
            // Needed for restriction check.
            request.setPnfsPath(_path.toString());
        }
    } else {
        request = new PnfsGetFileAttributes(_path.toString(), attr);
    }
    request.setAccessMask(mask);
    request.setUpdateAtime(true);
    ListenableFuture<PnfsGetFileAttributes> reply = _pnfs.requestAsync(request, timeout);
    setStatusUntil("PnfsManager: Fetching storage info", reply);
    return CellStub.transformAsync(reply, msg -> {
        FileAttributes attributes = msg.getFileAttributes();
        /* We can only transfer regular files.
                   */
        FileType type = attributes.getFileType();
        if (type == FileType.DIR || type == FileType.SPECIAL) {
            throw new NotFileCacheException("Not a regular file");
        }
        /* I/O mode must match completeness of the file.
                   */
        if (!attributes.getStorageInfo().isCreatedOnly()) {
            setWrite(false);
        } else if (allowWrite) {
            setWrite(true);
        } else {
            throw new FileIsNewCacheException();
        }
        setFileAttributes(attributes);
        return immediateFuture(null);
    });
}
Also used : NotFileCacheException(diskCacheV111.util.NotFileCacheException) FileType(org.dcache.namespace.FileType) PnfsId(diskCacheV111.util.PnfsId) PnfsGetFileAttributes(org.dcache.vehicles.PnfsGetFileAttributes) FileIsNewCacheException(diskCacheV111.util.FileIsNewCacheException) AccessMask(org.dcache.acl.enums.AccessMask) FileAttributes(org.dcache.vehicles.FileAttributes) PnfsGetFileAttributes(org.dcache.vehicles.PnfsGetFileAttributes) FileAttribute(org.dcache.namespace.FileAttribute)

Example 5 with NotFileCacheException

use of diskCacheV111.util.NotFileCacheException in project dcache by dCache.

the class AbstractFtpDoorV1Test method whenDeleNotFileReply550.

@Test
public void whenDeleNotFileReply550() throws Exception {
    doCallRealMethod().when(door).ftp_dele(anyString());
    doThrow(new NotFileCacheException("Not a File")).when(pnfs).deletePnfsEntry("/pathRoot/cwd/" + SRC_FILE, EnumSet.of(FileType.REGULAR, FileType.LINK));
    thrown.expectCode(550);
    door.ftp_dele(SRC_FILE);
}
Also used : NotFileCacheException(diskCacheV111.util.NotFileCacheException) Test(org.junit.Test)

Aggregations

NotFileCacheException (diskCacheV111.util.NotFileCacheException)6 CacheException (diskCacheV111.util.CacheException)3 FileExistsCacheException (diskCacheV111.util.FileExistsCacheException)3 FileIsNewCacheException (diskCacheV111.util.FileIsNewCacheException)3 FileNotFoundCacheException (diskCacheV111.util.FileNotFoundCacheException)3 FsPath (diskCacheV111.util.FsPath)3 NotDirCacheException (diskCacheV111.util.NotDirCacheException)3 PermissionDeniedCacheException (diskCacheV111.util.PermissionDeniedCacheException)3 InvalidMessageCacheException (diskCacheV111.util.InvalidMessageCacheException)2 PnfsId (diskCacheV111.util.PnfsId)2 TimeoutCacheException (diskCacheV111.util.TimeoutCacheException)2 FileType (org.dcache.namespace.FileType)2 FileAttributes (org.dcache.vehicles.FileAttributes)2 AttributeExistsCacheException (diskCacheV111.util.AttributeExistsCacheException)1 FileCorruptedCacheException (diskCacheV111.util.FileCorruptedCacheException)1 LockedCacheException (diskCacheV111.util.LockedCacheException)1 MissingResourceCacheException (diskCacheV111.util.MissingResourceCacheException)1 NoAttributeCacheException (diskCacheV111.util.NoAttributeCacheException)1 InetSocketAddress (java.net.InetSocketAddress)1 HashMap (java.util.HashMap)1