use of diskCacheV111.util.NotDirCacheException in project dcache by dCache.
the class ChimeraNameSpaceProvider method list.
@Override
public void list(Subject subject, String path, Glob glob, Range<Integer> range, Set<FileAttribute> attrs, ListHandler handler) throws CacheException {
try {
Pattern pattern = (glob == null) ? null : glob.toPattern();
ExtendedInode dir = pathToInode(subject, path);
if (!dir.isDirectory()) {
throw new NotDirCacheException("Not a directory: " + path);
}
if (!Subjects.isExemptFromNamespaceChecks(subject)) {
FileAttributes attributes = getFileAttributesForPermissionHandler(dir);
if (!dir.isDirectory()) {
throw new NotDirCacheException("Not a directory");
} else if (_permissionHandler.canListDir(subject, attributes) != ACCESS_ALLOWED) {
throw new PermissionDeniedCacheException("Access denied: " + path);
}
}
int counter = 0;
try (DirectoryStreamB<ChimeraDirectoryEntry> dirStream = dir.newDirectoryStream()) {
for (ChimeraDirectoryEntry entry : dirStream) {
try {
String name = entry.getName();
if (!name.equals(".") && !name.equals("..") && (pattern == null || pattern.matcher(name).matches()) && range.contains(counter++)) {
// FIXME: actually, ChimeraDirectoryEntry
// already contains most of attributes
FileAttributes fa = attrs.isEmpty() ? null : getFileAttributes(new ExtendedInode(_fs, entry.getInode()), attrs);
handler.addEntry(name, fa);
}
} catch (FileNotFoundChimeraFsException e) {
/* Not an error; files may be deleted during the
* list operation.
*/
}
}
}
} catch (FileNotFoundChimeraFsException e) {
throw new FileNotFoundCacheException("No such file or directory: " + path);
} catch (IOException e) {
LOGGER.error("Exception in list: {}", e);
throw new CacheException(CacheException.UNEXPECTED_SYSTEM_EXCEPTION, e.getMessage());
}
}
use of diskCacheV111.util.NotDirCacheException 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.NotDirCacheException in project dcache by dCache.
the class Inotify method lookup.
private PnfsId lookup(InotifySelector selector) throws CacheException {
FsPath path = selector.getFsPath();
PnfsHandler handler = new PnfsHandler(pnfsHandler, RequestUser.getSubject(), RequestUser.getRestriction());
FileAttributes attr = handler.getFileAttributes(path, EnumSet.of(PNFSID, TYPE));
if (attr.getFileType() == FileType.DIR) {
handler.getFileAttributes(path.toString(), // REVISIT update PnfsHandler to support FsPath here
EnumSet.noneOf(FileAttribute.class), EnumSet.of(AccessMask.LIST_DIRECTORY), false);
} else {
if (selector.flags().contains(AddWatchFlag.IN_ONLYDIR)) {
throw new NotDirCacheException("IN_ONLYDIR with " + attr.getFileType() + " target");
}
handler.getFileAttributes(path.toString(), EnumSet.noneOf(FileAttribute.class), EnumSet.of(AccessMask.READ_DATA), false);
}
return attr.getPnfsId();
}
use of diskCacheV111.util.NotDirCacheException in project dcache by dCache.
the class AbstractFtpDoorV1Test method whenRmdNotDirReply550.
@Test
public void whenRmdNotDirReply550() throws Exception {
doCallRealMethod().when(door).ftp_rmd(anyString());
doThrow(new NotDirCacheException("Not a directory")).when(pnfs).deletePnfsEntry("/pathRoot/cwd/" + OLD_DIR, EnumSet.of(FileType.DIR));
thrown.expectCode(550);
door.ftp_rmd(OLD_DIR);
}
use of diskCacheV111.util.NotDirCacheException in project dcache by dCache.
the class Storage method moveEntry.
@Override
public void moveEntry(SRMUser abstractUser, URI from, URI to) throws SRMException {
DcacheUser user = asDcacheUser(abstractUser);
PnfsHandler handler = new PnfsHandler(_pnfs, user.getSubject(), user.getRestriction());
FsPath fromPath = getPath(from);
FsPath toPath = getPath(to);
try {
try {
FileAttributes attr = handler.getFileAttributes(toPath.toString(), EnumSet.of(TYPE));
/* We now know the destination exists. In case the
* source and destination names are identical, we
* silently ignore the request.
*/
if (fromPath.equals(toPath)) {
return;
}
if (attr.getFileType() != FileType.DIR) {
throw new SRMDuplicationException("Destination exists");
}
toPath = toPath.child(fromPath.name());
} catch (FileNotFoundCacheException e) {
/* Destination name does not exist; not a problem.
*/
}
handler.renameEntry(fromPath.toString(), toPath.toString(), false);
} catch (FileNotFoundCacheException e) {
throw new SRMInvalidPathException("No such file or directory", e);
} catch (FileExistsCacheException e) {
throw new SRMDuplicationException("Destination exists", e);
} catch (NotDirCacheException e) {
/* The parent of the target name did not exist or was not
* a directory.
*/
FsPath parent = toPath.parent();
throw new SRMInvalidPathException("No such directory: " + parent, e);
} catch (PermissionDeniedCacheException e) {
throw new SRMAuthorizationException("Permission denied");
} catch (TimeoutCacheException e) {
_log.error("Failed to rename {} due to timeout", fromPath);
throw new SRMInternalErrorException("Internal name space timeout");
} catch (CacheException e) {
_log.error("Failed to rename {}: {}", fromPath, e.getMessage());
throw new SRMException(String.format("Rename failed [rc=%d,msg=%s]", e.getRc(), e.getMessage()));
}
}
Aggregations