Search in sources :

Example 1 with NotDirChimeraException

use of org.dcache.chimera.NotDirChimeraException in project dcache by dCache.

the class ChimeraVfs method link.

@Override
public Inode link(Inode parent, Inode link, String path, Subject subject) throws IOException {
    FsInode parentFsInode = toFsInode(parent);
    FsInode linkInode = toFsInode(link);
    try {
        FsInode fsInode = _fs.createHLink(parentFsInode, linkInode, path);
        return toInode(fsInode);
    } catch (NotDirChimeraException e) {
        throw new NotDirException("parent not a directory");
    } catch (FileExistsChimeraFsException e) {
        throw new ExistException("path already exists");
    }
}
Also used : NotDirException(org.dcache.nfs.status.NotDirException) NotDirChimeraException(org.dcache.chimera.NotDirChimeraException) FsInode(org.dcache.chimera.FsInode) ExistException(org.dcache.nfs.status.ExistException) FileExistsChimeraFsException(org.dcache.chimera.FileExistsChimeraFsException)

Example 2 with NotDirChimeraException

use of org.dcache.chimera.NotDirChimeraException in project dcache by dCache.

the class ChimeraVfs method move.

@Override
public boolean move(Inode src, String oldName, Inode dest, String newName) throws IOException {
    FsInode from = toFsInode(src);
    FsInode to = toFsInode(dest);
    try {
        return _fs.rename(_fs.inodeOf(from, oldName, NO_STAT), from, oldName, to, newName);
    } catch (NotDirChimeraException e) {
        throw new NotDirException("not a directory");
    } catch (FileExistsChimeraFsException e) {
        throw new ExistException("destination exists");
    } catch (DirNotEmptyChimeraFsException e) {
        throw new NotEmptyException("directory exist and not empty");
    } catch (FileNotFoundChimeraFsException e) {
        throw new NoEntException("file not found");
    } catch (PermissionDeniedChimeraFsException e) {
        throw new PermException(e.getMessage());
    }
}
Also used : FileNotFoundChimeraFsException(org.dcache.chimera.FileNotFoundChimeraFsException) NotDirException(org.dcache.nfs.status.NotDirException) PermissionDeniedChimeraFsException(org.dcache.chimera.PermissionDeniedChimeraFsException) NotDirChimeraException(org.dcache.chimera.NotDirChimeraException) FsInode(org.dcache.chimera.FsInode) NoEntException(org.dcache.nfs.status.NoEntException) PermException(org.dcache.nfs.status.PermException) NotEmptyException(org.dcache.nfs.status.NotEmptyException) DirNotEmptyChimeraFsException(org.dcache.chimera.DirNotEmptyChimeraFsException) ExistException(org.dcache.nfs.status.ExistException) FileExistsChimeraFsException(org.dcache.chimera.FileExistsChimeraFsException)

Example 3 with NotDirChimeraException

use of org.dcache.chimera.NotDirChimeraException in project dcache by dCache.

the class ChimeraNameSpaceProvider method createSymLink.

@Override
public PnfsId createSymLink(Subject subject, String path, String dest, FileAttributes assignAttributes) throws CacheException {
    checkArgument(assignAttributes.isUndefined(INVALID_CREATE_SYM_LINK_ATTRIBUTES), "Illegal assign attributes: %s", assignAttributes.getDefinedAttributes());
    try {
        File newEntryFile = new File(path);
        String parentPath = newEntryFile.getParent();
        if (parentPath == null) {
            throw new FileExistsCacheException("File exists: " + path);
        }
        ExtendedInode parent = pathToInode(subject, parentPath);
        if (!Subjects.isExemptFromNamespaceChecks(subject)) {
            FileAttributes attributes = getFileAttributesForPermissionHandler(parent);
            if (_permissionHandler.canCreateFile(subject, attributes) != ACCESS_ALLOWED) {
                throw new PermissionDeniedCacheException("Access denied: " + path);
            }
        }
        FsInode inode;
        try {
            int uid = assignAttributes.getOwnerIfPresent().orElseGet(() -> defaultUid(subject, parent));
            int gid = assignAttributes.getGroupIfPresent().orElseGet(() -> defaultGid(subject, parent));
            int mode = assignAttributes.getModeIfPresent().orElse(SYMLINK_MODE);
            assignAttributes.undefine(OWNER, OWNER_GROUP, MODE);
            inode = _fs.createLink(parent, newEntryFile.getName(), uid, gid, mode, dest.getBytes(UTF_8));
        } catch (UncheckedIOException e) {
            throw e.getCause();
        }
        PnfsId pnfsid = new PnfsId(inode.getId());
        if (!assignAttributes.getDefinedAttributes().isEmpty()) {
            setFileAttributes(subject, pnfsid, assignAttributes, EnumSet.noneOf(FileAttribute.class));
        }
        return pnfsid;
    } catch (NotDirChimeraException e) {
        throw new NotDirCacheException("Not a directory: " + path);
    } catch (FileNotFoundChimeraFsException e) {
        throw new FileNotFoundCacheException("No such file or directory: " + path);
    } catch (FileExistsChimeraFsException e) {
        throw new FileExistsCacheException("File exists: " + path);
    } catch (IOException e) {
        throw new CacheException(CacheException.UNEXPECTED_SYSTEM_EXCEPTION, e.getMessage());
    }
}
Also used : 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) NotDirChimeraException(org.dcache.chimera.NotDirChimeraException) PnfsId(diskCacheV111.util.PnfsId) UncheckedIOException(java.io.UncheckedIOException) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) FileExistsChimeraFsException(org.dcache.chimera.FileExistsChimeraFsException) FileNotFoundChimeraFsException(org.dcache.chimera.FileNotFoundChimeraFsException) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) FsInode(org.dcache.chimera.FsInode) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) File(java.io.File) FileAttributes(org.dcache.vehicles.FileAttributes) NotDirCacheException(diskCacheV111.util.NotDirCacheException) FileExistsCacheException(diskCacheV111.util.FileExistsCacheException) FileAttribute(org.dcache.namespace.FileAttribute)

Example 4 with NotDirChimeraException

use of org.dcache.chimera.NotDirChimeraException in project dcache by dCache.

the class ChimeraNameSpaceProvider method createDirectory.

@Override
public PnfsId createDirectory(Subject subject, String path, FileAttributes attributes) throws CacheException {
    checkArgument(attributes.isUndefined(INVALID_CREATE_DIRECTORY_ATTRIBUTES), "Illegal assign attributes: %s", attributes.getDefinedAttributes());
    try {
        File newEntryFile = new File(path);
        String parentPath = newEntryFile.getParent();
        if (parentPath == null) {
            throw new FileExistsCacheException("File exists: " + path);
        }
        ExtendedInode parent = pathToInode(subject, parentPath);
        ExtendedInode inode;
        try {
            int uid = attributes.getOwnerIfPresent().orElseGet(() -> defaultUid(subject, parent));
            int gid = attributes.getGroupIfPresent().orElseGet(() -> defaultGid(subject, parent));
            int mode = attributes.getModeIfPresent().orElse(parent.statCache().getMode() & UMASK_DIR);
            attributes.undefine(OWNER, OWNER_GROUP, MODE);
            inode = mkdir(subject, parent, newEntryFile.getName(), uid, gid, mode);
        } catch (UncheckedIOException e) {
            throw e.getCause();
        }
        if (!attributes.getDefinedAttributes().isEmpty()) {
            setFileAttributes(subject, inode.getPnfsId(), attributes, EnumSet.noneOf(FileAttribute.class));
        }
        return inode.getPnfsId();
    } catch (NotDirChimeraException e) {
        throw new NotDirCacheException("Not a directory: " + path);
    } catch (FileNotFoundChimeraFsException e) {
        throw new FileNotFoundCacheException("No such file or directory: " + path);
    } catch (FileExistsChimeraFsException e) {
        throw new FileExistsCacheException("File exists: " + path);
    } catch (IOException e) {
        throw new CacheException(CacheException.UNEXPECTED_SYSTEM_EXCEPTION, e.getMessage());
    }
}
Also used : 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) NotDirChimeraException(org.dcache.chimera.NotDirChimeraException) UncheckedIOException(java.io.UncheckedIOException) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) FileExistsChimeraFsException(org.dcache.chimera.FileExistsChimeraFsException) FileNotFoundChimeraFsException(org.dcache.chimera.FileNotFoundChimeraFsException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) File(java.io.File) NotDirCacheException(diskCacheV111.util.NotDirCacheException) FileExistsCacheException(diskCacheV111.util.FileExistsCacheException) FileAttribute(org.dcache.namespace.FileAttribute)

Example 5 with NotDirChimeraException

use of org.dcache.chimera.NotDirChimeraException in project dcache by dCache.

the class ChimeraNameSpaceProvider method createFile.

@Override
public FileAttributes createFile(Subject subject, String path, FileAttributes assignAttributes, Set<FileAttribute> requestedAttributes) throws CacheException {
    checkArgument(assignAttributes.isUndefined(INVALID_CREATE_FILE_ATTRIBUTES), "Illegal assign attributes: %s", assignAttributes.getDefinedAttributes());
    File newEntryFile = new File(path);
    String parentPath = newEntryFile.getParent();
    try {
        if (parentPath == null) {
            throw new FileExistsCacheException("File exists: " + path);
        }
        ExtendedInode parent = pathToInode(subject, parentPath);
        if (!Subjects.isExemptFromNamespaceChecks(subject)) {
            FileAttributes attributes = getFileAttributesForPermissionHandler(parent);
            if (_permissionHandler.canCreateFile(subject, attributes) != ACCESS_ALLOWED) {
                throw new PermissionDeniedCacheException("Access denied: " + path);
            }
        }
        ExtendedInode inode;
        try {
            int uid = assignAttributes.getOwnerIfPresent().orElseGet(() -> defaultUid(subject, parent));
            int gid = assignAttributes.getGroupIfPresent().orElseGet(() -> defaultGid(subject, parent));
            int mode = assignAttributes.getModeIfPresent().orElse(parent.statCache().getMode() & UMASK_FILE);
            assignAttributes.undefine(OWNER, OWNER_GROUP, MODE);
            inode = parent.create(newEntryFile.getName(), uid, gid, mode);
        } catch (UncheckedIOException e) {
            throw e.getCause();
        }
        FileAttributes fileAttributes;
        if (assignAttributes.getDefinedAttributes().isEmpty()) {
            fileAttributes = getFileAttributes(inode, requestedAttributes);
        } else {
            fileAttributes = setFileAttributes(subject, inode.getPnfsId(), assignAttributes, requestedAttributes);
        }
        if (parent.getTags().containsKey(TAG_EXPECTED_SIZE)) {
            ImmutableList<String> size = parent.getTag(TAG_EXPECTED_SIZE);
            if (!size.isEmpty()) {
                fileAttributes.setSize(Long.parseLong(size.get(0)));
            }
        }
        return fileAttributes;
    } catch (NotDirChimeraException e) {
        throw new NotDirCacheException("Not a directory: " + parentPath);
    } catch (FileNotFoundChimeraFsException e) {
        throw new FileNotFoundCacheException("No such directory: " + parentPath);
    } catch (FileExistsChimeraFsException e) {
        throw new FileExistsCacheException("File exists: " + path);
    } catch (IOException e) {
        throw new CacheException(CacheException.UNEXPECTED_SYSTEM_EXCEPTION, e.getMessage());
    }
}
Also used : 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) NotDirChimeraException(org.dcache.chimera.NotDirChimeraException) UncheckedIOException(java.io.UncheckedIOException) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) FileExistsChimeraFsException(org.dcache.chimera.FileExistsChimeraFsException) FileNotFoundChimeraFsException(org.dcache.chimera.FileNotFoundChimeraFsException) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) File(java.io.File) FileAttributes(org.dcache.vehicles.FileAttributes) NotDirCacheException(diskCacheV111.util.NotDirCacheException) FileExistsCacheException(diskCacheV111.util.FileExistsCacheException)

Aggregations

FileExistsChimeraFsException (org.dcache.chimera.FileExistsChimeraFsException)5 NotDirChimeraException (org.dcache.chimera.NotDirChimeraException)5 FileNotFoundChimeraFsException (org.dcache.chimera.FileNotFoundChimeraFsException)4 AttributeExistsCacheException (diskCacheV111.util.AttributeExistsCacheException)3 CacheException (diskCacheV111.util.CacheException)3 FileCorruptedCacheException (diskCacheV111.util.FileCorruptedCacheException)3 FileExistsCacheException (diskCacheV111.util.FileExistsCacheException)3 FileIsNewCacheException (diskCacheV111.util.FileIsNewCacheException)3 FileNotFoundCacheException (diskCacheV111.util.FileNotFoundCacheException)3 InvalidMessageCacheException (diskCacheV111.util.InvalidMessageCacheException)3 LockedCacheException (diskCacheV111.util.LockedCacheException)3 NoAttributeCacheException (diskCacheV111.util.NoAttributeCacheException)3 NotDirCacheException (diskCacheV111.util.NotDirCacheException)3 NotFileCacheException (diskCacheV111.util.NotFileCacheException)3 PermissionDeniedCacheException (diskCacheV111.util.PermissionDeniedCacheException)3 File (java.io.File)3 IOException (java.io.IOException)3 UncheckedIOException (java.io.UncheckedIOException)3 FsInode (org.dcache.chimera.FsInode)3 FileAttribute (org.dcache.namespace.FileAttribute)2