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