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