use of org.dcache.chimera.NoXdataChimeraException in project dcache by dCache.
the class ChimeraVfs method getXattr.
@Override
public byte[] getXattr(Inode inode, String attr) throws IOException {
FsInode fsInode = toFsInode(inode);
try {
if (attr.startsWith(XATTR_TAG_PREFIX) && fsInode.isDirectory()) {
String tagName = attr.substring(XATTR_TAG_PREFIX.length());
byte[] buf = new byte[1024];
int n = _fs.getTag(fsInode, tagName, buf, 0, buf.length);
if (n == 0) {
throw new NoXattrException("tag doesn't exist or empty");
}
return Arrays.copyOf(buf, n);
}
// try dcache dot files first
var dcache_attr = SpecialXattrs.byName(attr);
if (dcache_attr.isPresent()) {
return dcache_attr.get().read(fsInode);
}
// just a regular extended attribute
return _fs.getXattr(fsInode, attr);
} catch (NoXdataChimeraException e) {
throw new NoXattrException(e.getMessage(), e);
}
}
use of org.dcache.chimera.NoXdataChimeraException in project dcache by dCache.
the class ChimeraVfs method removeXattr.
@Override
public void removeXattr(Inode inode, String attr) throws IOException {
FsInode fsInode = toFsInode(inode);
// try dcache dot files first
var dcache_attr = SpecialXattrs.byName(attr);
if (dcache_attr.isPresent()) {
throw new PermException("Can't remove dCache attribute");
}
try {
if (attr.startsWith(XATTR_TAG_PREFIX) && fsInode.isDirectory()) {
String tagName = attr.substring(XATTR_TAG_PREFIX.length());
_fs.removeTag(fsInode, tagName);
} else {
_fs.removeXattr(fsInode, attr);
}
} catch (NoXdataChimeraException e) {
throw new NoXattrException(e.getMessage(), e);
}
}
use of org.dcache.chimera.NoXdataChimeraException 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.NoXdataChimeraException in project dcache by dCache.
the class ChimeraVfs method setXattr.
@Override
public void setXattr(Inode inode, String attr, byte[] value, SetXattrMode mode) throws IOException {
FsInode fsInode = toFsInode(inode);
// try dcache dot files first
var dcache_attr = SpecialXattrs.byName(attr);
if (dcache_attr.isPresent()) {
dcache_attr.get().set(fsInode, value);
return;
}
try {
if (attr.startsWith(XATTR_TAG_PREFIX) && fsInode.isDirectory()) {
String tagName = attr.substring(XATTR_TAG_PREFIX.length());
if (mode == SetXattrMode.CREATE) {
_fs.createTag(fsInode, tagName);
}
if (mode == SetXattrMode.EITHER) {
try {
_fs.statTag(fsInode, tagName);
} catch (FileNotFoundChimeraFsException e) {
_fs.createTag(fsInode, tagName);
}
}
_fs.setTag(fsInode, tagName, value, 0, value.length);
} else {
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(fsInode, attr, value, m);
}
} catch (NoXdataChimeraException e) {
throw new NoXattrException(e.getMessage(), e);
} catch (FileExistsChimeraFsException e) {
throw new ExistException(e.getMessage(), e);
}
}
use of org.dcache.chimera.NoXdataChimeraException in project dcache by dCache.
the class ChimeraNameSpaceProvider method removeExtendedAttribute.
public void removeExtendedAttribute(Subject subject, FsPath path, String name) 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");
}
}
}
_fs.removeXattr(target, name);
} catch (FileNotFoundChimeraFsException e) {
throw new FileNotFoundCacheException("No such file " + path);
} catch (NoXdataChimeraException e) {
throw new NoAttributeCacheException("No attribute " + name + " for file " + path, e);
} catch (ChimeraFsException e) {
throw new CacheException("Failed to list extended attributes: " + Exceptions.messageOrClassName(e), e);
}
}
Aggregations