use of org.dcache.chimera.ChimeraFsException in project dcache by dCache.
the class ChimeraNameSpaceProvider method clearCacheLocation.
@Override
public void clearCacheLocation(Subject subject, PnfsId pnfsId, String cacheLocation, boolean removeIfLast) throws CacheException {
LOGGER.debug("clearCacheLocation : {} for {}", cacheLocation, pnfsId);
try {
ExtendedInode inode = new ExtendedInode(_fs, pnfsId, NO_STAT);
_fs.clearInodeLocation(inode, StorageGenericLocation.DISK, cacheLocation);
if (removeIfLast) {
List<StorageLocatable> locations = _fs.getInodeLocations(inode, StorageGenericLocation.DISK);
if (locations.isEmpty()) {
LOGGER.debug("last location cleaned. removing file {}", inode);
_fs.remove(inode);
}
}
} catch (FileNotFoundChimeraFsException e) {
throw new FileNotFoundCacheException("No such file or directory: " + pnfsId, e);
} catch (ChimeraFsException e) {
LOGGER.error("Exception in clearCacheLocation for {} : {}", pnfsId, e);
throw new CacheException(CacheException.UNEXPECTED_SYSTEM_EXCEPTION, e.getMessage());
}
}
use of org.dcache.chimera.ChimeraFsException in project dcache by dCache.
the class ChimeraNameSpaceProvider method cancelUpload.
@Override
public Collection<FileAttributes> cancelUpload(Subject subject, FsPath temporaryPath, FsPath finalPath, Set<FileAttribute> requested, String explanation) throws CacheException {
List<FileAttributes> deleted = new ArrayList();
try {
FsPath temporaryDir = getParentOfFile(temporaryPath);
checkIsTemporaryDirectory(temporaryPath, temporaryDir);
/* Temporary upload directory must exist.
*/
ExtendedInode uploadDirInode;
try {
uploadDirInode = new ExtendedInode(_fs, _fs.path2inode(temporaryDir.parent().toString()));
} catch (FileNotFoundChimeraFsException e) {
throw new FileNotFoundCacheException("No such file or directory: " + temporaryDir, e);
}
/* Delete temporary upload directory and any files in it.
*/
String name = temporaryPath.parent().name();
removeRecursively(uploadDirInode, name, uploadDirInode.inodeOf(name, STAT), i -> {
try {
if (i.getFileType() == FileType.REGULAR) {
deleted.add(getFileAttributes(i, requested));
}
} catch (CacheException | ChimeraFsException e) {
LOGGER.info("Unable to identify deleted file for upload cancellation: {}", e.toString());
}
});
} catch (ChimeraFsException e) {
throw new CacheException(CacheException.UNEXPECTED_SYSTEM_EXCEPTION, e.getMessage());
}
return deleted;
}
use of org.dcache.chimera.ChimeraFsException in project dcache by dCache.
the class ChimeraNameSpaceProvider method writeExtendedAttribute.
public void writeExtendedAttribute(Subject subject, FsPath path, String name, byte[] value, SetExtendedAttributeMode mode) throws CacheException {
try {
ExtendedInode target = pathToInode(subject, path.toString());
if (!Subjects.isExemptFromNamespaceChecks(subject)) {
FileAttributes attributes = getFileAttributesForPermissionHandler(target);
if (target.isDirectory()) {
if (_permissionHandler.canCreateFile(subject, attributes) != ACCESS_ALLOWED) {
throw new PermissionDeniedCacheException("Access denied");
}
} else {
if (_permissionHandler.canWriteFile(subject, attributes) != ACCESS_ALLOWED) {
throw new PermissionDeniedCacheException("Access denied");
}
}
}
FileSystemProvider.SetXattrMode m;
switch(mode) {
case CREATE:
m = FileSystemProvider.SetXattrMode.CREATE;
break;
case REPLACE:
m = FileSystemProvider.SetXattrMode.REPLACE;
break;
case EITHER:
m = FileSystemProvider.SetXattrMode.EITHER;
break;
default:
throw new RuntimeException();
}
_fs.setXattr(target, name, value, m);
} catch (NoXdataChimeraException e) {
throw new NoAttributeCacheException(e.getMessage(), e);
} catch (FileExistsChimeraFsException e) {
throw new AttributeExistsCacheException(e.getMessage(), e);
} catch (FileNotFoundChimeraFsException e) {
throw new FileNotFoundCacheException("No such file " + path);
} catch (ChimeraFsException e) {
throw new CacheException("Failed to list extended attributes: " + Exceptions.messageOrClassName(e), e);
}
}
use of org.dcache.chimera.ChimeraFsException 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 org.dcache.chimera.ChimeraFsException in project dcache by dCache.
the class ChimeraNameSpaceProvider method commitUpload.
@Override
public FileAttributes commitUpload(Subject subject, FsPath temporaryPath, FsPath finalPath, Set<CreateOption> options, Set<FileAttribute> attributesToFetch) throws CacheException {
try {
FsPath temporaryDir = getParentOfFile(temporaryPath);
FsPath finalDir = getParentOfFile(finalPath);
checkIsTemporaryDirectory(temporaryPath, temporaryDir);
/* File must have been created...
*/
ExtendedInode uploadDirInode;
ExtendedInode temporaryDirInode;
ExtendedInode inodeOfFile;
try {
uploadDirInode = new ExtendedInode(_fs, _fs.path2inode(temporaryDir.parent().toString()));
temporaryDirInode = uploadDirInode.inodeOf(temporaryDir.name(), STAT);
inodeOfFile = temporaryDirInode.inodeOf(temporaryPath.name(), STAT);
} catch (FileNotFoundChimeraFsException e) {
throw new FileNotFoundCacheException("No such file or directory: " + temporaryPath, e);
}
/* ...and upload must have completed...
*/
ImmutableList<StorageLocatable> locations = inodeOfFile.getLocations();
if (locations.isEmpty()) {
throw new FileIsNewCacheException("Upload has not completed.");
}
/* ...and it must have the correct size.
*/
ImmutableList<String> size = inodeOfFile.getTag(TAG_EXPECTED_SIZE);
if (!size.isEmpty()) {
long expectedSize = Long.parseLong(size.get(0));
long actualSize = inodeOfFile.statCache().getSize();
if (expectedSize != actualSize) {
throw new FileCorruptedCacheException(expectedSize, actualSize);
}
}
/* Target directory must exist.
*/
ExtendedInode finalDirInode;
try {
finalDirInode = new ExtendedInode(_fs, _fs.path2inode(finalDir.toString()));
} catch (FileNotFoundChimeraFsException e) {
throw new FileNotFoundCacheException("No such file or directory: " + finalDir, e);
}
/* File must not exist unless overwrite is enabled.
*/
try {
ExtendedInode inodeOfExistingFile = finalDirInode.inodeOf(finalPath.name(), STAT);
if (!options.contains(CreateOption.OVERWRITE_EXISTING)) {
throw new FileExistsCacheException("File exists: " + finalPath);
}
/* User must be authorized to delete existing file.
*/
if (!Subjects.isExemptFromNamespaceChecks(subject)) {
FileAttributes attributesOfParent = getFileAttributesForPermissionHandler(finalDirInode);
FileAttributes attributesOfFile = getFileAttributesForPermissionHandler(inodeOfExistingFile);
if (_permissionHandler.canDeleteFile(subject, attributesOfParent, attributesOfFile) != ACCESS_ALLOWED) {
throw new PermissionDeniedCacheException("Overwrite denied: " + finalPath);
}
}
} catch (FileNotFoundChimeraFsException ignored) {
}
/* Read file attributes before moving the file. Otherwise the cached parent will
* be gone.
*/
FileAttributes attributes = getFileAttributes(inodeOfFile, attributesToFetch);
/* File is moved to correct directory.
*/
_fs.rename(inodeOfFile, temporaryDirInode, temporaryPath.name(), finalDirInode, finalPath.name());
/* Delete temporary upload directory and any files in it.
*/
removeRecursively(uploadDirInode, temporaryDir.name(), temporaryDirInode, i -> {
});
return attributes;
} catch (ChimeraFsException e) {
throw new CacheException(CacheException.UNEXPECTED_SYSTEM_EXCEPTION, e.getMessage());
} catch (NumberFormatException e) {
throw new FileCorruptedCacheException("Failed to commit file: " + e.getMessage());
}
}
Aggregations