Search in sources :

Example 1 with NotDirCacheException

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

the class ChimeraNameSpaceProvider method list.

@Override
public void list(Subject subject, String path, Glob glob, Range<Integer> range, Set<FileAttribute> attrs, ListHandler handler) throws CacheException {
    try {
        Pattern pattern = (glob == null) ? null : glob.toPattern();
        ExtendedInode dir = pathToInode(subject, path);
        if (!dir.isDirectory()) {
            throw new NotDirCacheException("Not a directory: " + path);
        }
        if (!Subjects.isExemptFromNamespaceChecks(subject)) {
            FileAttributes attributes = getFileAttributesForPermissionHandler(dir);
            if (!dir.isDirectory()) {
                throw new NotDirCacheException("Not a directory");
            } else if (_permissionHandler.canListDir(subject, attributes) != ACCESS_ALLOWED) {
                throw new PermissionDeniedCacheException("Access denied: " + path);
            }
        }
        int counter = 0;
        try (DirectoryStreamB<ChimeraDirectoryEntry> dirStream = dir.newDirectoryStream()) {
            for (ChimeraDirectoryEntry entry : dirStream) {
                try {
                    String name = entry.getName();
                    if (!name.equals(".") && !name.equals("..") && (pattern == null || pattern.matcher(name).matches()) && range.contains(counter++)) {
                        // FIXME: actually, ChimeraDirectoryEntry
                        // already contains most of attributes
                        FileAttributes fa = attrs.isEmpty() ? null : getFileAttributes(new ExtendedInode(_fs, entry.getInode()), attrs);
                        handler.addEntry(name, fa);
                    }
                } catch (FileNotFoundChimeraFsException e) {
                /* Not an error; files may be deleted during the
                         * list operation.
                         */
                }
            }
        }
    } catch (FileNotFoundChimeraFsException e) {
        throw new FileNotFoundCacheException("No such file or directory: " + path);
    } catch (IOException e) {
        LOGGER.error("Exception in list: {}", e);
        throw new CacheException(CacheException.UNEXPECTED_SYSTEM_EXCEPTION, e.getMessage());
    }
}
Also used : Pattern(java.util.regex.Pattern) 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) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) FileNotFoundChimeraFsException(org.dcache.chimera.FileNotFoundChimeraFsException) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) NotDirCacheException(diskCacheV111.util.NotDirCacheException) FileAttributes(org.dcache.vehicles.FileAttributes) ChimeraDirectoryEntry(org.dcache.chimera.ChimeraDirectoryEntry)

Example 2 with NotDirCacheException

use of diskCacheV111.util.NotDirCacheException 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 NotDirCacheException

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

the class Inotify method lookup.

private PnfsId lookup(InotifySelector selector) throws CacheException {
    FsPath path = selector.getFsPath();
    PnfsHandler handler = new PnfsHandler(pnfsHandler, RequestUser.getSubject(), RequestUser.getRestriction());
    FileAttributes attr = handler.getFileAttributes(path, EnumSet.of(PNFSID, TYPE));
    if (attr.getFileType() == FileType.DIR) {
        handler.getFileAttributes(path.toString(), // REVISIT update PnfsHandler to support FsPath here
        EnumSet.noneOf(FileAttribute.class), EnumSet.of(AccessMask.LIST_DIRECTORY), false);
    } else {
        if (selector.flags().contains(AddWatchFlag.IN_ONLYDIR)) {
            throw new NotDirCacheException("IN_ONLYDIR with " + attr.getFileType() + " target");
        }
        handler.getFileAttributes(path.toString(), EnumSet.noneOf(FileAttribute.class), EnumSet.of(AccessMask.READ_DATA), false);
    }
    return attr.getPnfsId();
}
Also used : PnfsHandler(diskCacheV111.util.PnfsHandler) FileAttributes(org.dcache.vehicles.FileAttributes) NotDirCacheException(diskCacheV111.util.NotDirCacheException) FsPath(diskCacheV111.util.FsPath) FileAttribute(org.dcache.namespace.FileAttribute)

Example 4 with NotDirCacheException

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

the class AbstractFtpDoorV1Test method whenRmdNotDirReply550.

@Test
public void whenRmdNotDirReply550() throws Exception {
    doCallRealMethod().when(door).ftp_rmd(anyString());
    doThrow(new NotDirCacheException("Not a directory")).when(pnfs).deletePnfsEntry("/pathRoot/cwd/" + OLD_DIR, EnumSet.of(FileType.DIR));
    thrown.expectCode(550);
    door.ftp_rmd(OLD_DIR);
}
Also used : NotDirCacheException(diskCacheV111.util.NotDirCacheException) Test(org.junit.Test)

Example 5 with NotDirCacheException

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

the class Storage method moveEntry.

@Override
public void moveEntry(SRMUser abstractUser, URI from, URI to) throws SRMException {
    DcacheUser user = asDcacheUser(abstractUser);
    PnfsHandler handler = new PnfsHandler(_pnfs, user.getSubject(), user.getRestriction());
    FsPath fromPath = getPath(from);
    FsPath toPath = getPath(to);
    try {
        try {
            FileAttributes attr = handler.getFileAttributes(toPath.toString(), EnumSet.of(TYPE));
            /* We now know the destination exists. In case the
                 * source and destination names are identical, we
                 * silently ignore the request.
                 */
            if (fromPath.equals(toPath)) {
                return;
            }
            if (attr.getFileType() != FileType.DIR) {
                throw new SRMDuplicationException("Destination exists");
            }
            toPath = toPath.child(fromPath.name());
        } catch (FileNotFoundCacheException e) {
        /* Destination name does not exist; not a problem.
                 */
        }
        handler.renameEntry(fromPath.toString(), toPath.toString(), false);
    } catch (FileNotFoundCacheException e) {
        throw new SRMInvalidPathException("No such file or directory", e);
    } catch (FileExistsCacheException e) {
        throw new SRMDuplicationException("Destination exists", e);
    } catch (NotDirCacheException e) {
        /* The parent of the target name did not exist or was not
             * a directory.
             */
        FsPath parent = toPath.parent();
        throw new SRMInvalidPathException("No such directory: " + parent, e);
    } catch (PermissionDeniedCacheException e) {
        throw new SRMAuthorizationException("Permission denied");
    } catch (TimeoutCacheException e) {
        _log.error("Failed to rename {} due to timeout", fromPath);
        throw new SRMInternalErrorException("Internal name space timeout");
    } catch (CacheException e) {
        _log.error("Failed to rename {}: {}", fromPath, e.getMessage());
        throw new SRMException(String.format("Rename failed [rc=%d,msg=%s]", e.getRc(), e.getMessage()));
    }
}
Also used : SRMAuthorizationException(org.dcache.srm.SRMAuthorizationException) FileIsNewCacheException(diskCacheV111.util.FileIsNewCacheException) FileExistsCacheException(diskCacheV111.util.FileExistsCacheException) NotDirCacheException(diskCacheV111.util.NotDirCacheException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) TimeoutCacheException(diskCacheV111.util.TimeoutCacheException) CacheException(diskCacheV111.util.CacheException) FileCorruptedCacheException(diskCacheV111.util.FileCorruptedCacheException) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) SRMInvalidPathException(org.dcache.srm.SRMInvalidPathException) PnfsHandler(diskCacheV111.util.PnfsHandler) SRMInternalErrorException(org.dcache.srm.SRMInternalErrorException) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) SRMException(org.dcache.srm.SRMException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) FileAttributes(org.dcache.vehicles.FileAttributes) NotDirCacheException(diskCacheV111.util.NotDirCacheException) SRMDuplicationException(org.dcache.srm.SRMDuplicationException) FileExistsCacheException(diskCacheV111.util.FileExistsCacheException) FsPath(diskCacheV111.util.FsPath) TimeoutCacheException(diskCacheV111.util.TimeoutCacheException)

Aggregations

NotDirCacheException (diskCacheV111.util.NotDirCacheException)24 CacheException (diskCacheV111.util.CacheException)21 FileNotFoundCacheException (diskCacheV111.util.FileNotFoundCacheException)21 PermissionDeniedCacheException (diskCacheV111.util.PermissionDeniedCacheException)21 FileExistsCacheException (diskCacheV111.util.FileExistsCacheException)19 TimeoutCacheException (diskCacheV111.util.TimeoutCacheException)14 FsPath (diskCacheV111.util.FsPath)13 NotFileCacheException (diskCacheV111.util.NotFileCacheException)13 FileCorruptedCacheException (diskCacheV111.util.FileCorruptedCacheException)12 FileIsNewCacheException (diskCacheV111.util.FileIsNewCacheException)12 FileAttributes (org.dcache.vehicles.FileAttributes)10 MissingResourceCacheException (diskCacheV111.util.MissingResourceCacheException)8 IOException (java.io.IOException)8 SRMAuthorizationException (org.dcache.srm.SRMAuthorizationException)7 SRMException (org.dcache.srm.SRMException)7 SRMInternalErrorException (org.dcache.srm.SRMInternalErrorException)7 SRMInvalidPathException (org.dcache.srm.SRMInvalidPathException)7 InvalidMessageCacheException (diskCacheV111.util.InvalidMessageCacheException)6 AttributeExistsCacheException (diskCacheV111.util.AttributeExistsCacheException)5 LockedCacheException (diskCacheV111.util.LockedCacheException)5