use of java.nio.file.InvalidPathException in project alluxio by Alluxio.
the class AlluxioFuseFileSystem method readdirInternal.
private int readdirInternal(String path, Pointer buff, FuseFillDir filter, @off_t long offset, FuseFileInfo fi) {
final AlluxioURI turi = mPathResolverCache.getUnchecked(path);
try {
final List<URIStatus> ls = mFileSystem.listStatus(turi);
// standard . and .. entries
filter.apply(buff, ".", null, 0);
filter.apply(buff, "..", null, 0);
for (final URIStatus file : ls) {
filter.apply(buff, file.getName(), null, 0);
}
} catch (FileDoesNotExistException | InvalidPathException e) {
LOG.debug("Failed to read directory {}, path does not exist or is invalid", path);
return -ErrorCodes.ENOENT();
} catch (Throwable t) {
LOG.error("Failed to read directory {}", path, t);
return AlluxioFuseUtils.getErrorCode(t);
}
return 0;
}
use of java.nio.file.InvalidPathException in project alluxio by Alluxio.
the class AlluxioFuseFileSystem method createInternal.
private int createInternal(String path, @mode_t long mode, FuseFileInfo fi) {
final AlluxioURI uri = mPathResolverCache.getUnchecked(path);
if (uri.getName().length() > MAX_NAME_LENGTH) {
LOG.error("Failed to create {}, file name is longer than {} characters", path, MAX_NAME_LENGTH);
return -ErrorCodes.ENAMETOOLONG();
}
try {
if (mOpenFiles.size() >= MAX_OPEN_FILES) {
LOG.error("Cannot create {}: too many open files (MAX_OPEN_FILES: {})", path, MAX_OPEN_FILES);
return -ErrorCodes.EMFILE();
}
SetAttributePOptions.Builder attributeOptionsBuilder = SetAttributePOptions.newBuilder();
FuseContext fc = getContext();
long uid = fc.uid.get();
long gid = fc.gid.get();
if (gid != GID) {
String groupName = AlluxioFuseUtils.getGroupName(gid);
if (groupName.isEmpty()) {
// This should never be reached since input gid is always valid
LOG.error("Failed to get group name from gid {}.", gid);
return -ErrorCodes.EFAULT();
}
attributeOptionsBuilder.setGroup(groupName);
}
if (uid != UID) {
String userName = AlluxioFuseUtils.getUserName(uid);
if (userName.isEmpty()) {
// This should never be reached since input uid is always valid
LOG.error("Failed to get user name from uid {}", uid);
return -ErrorCodes.EFAULT();
}
attributeOptionsBuilder.setOwner(userName);
}
SetAttributePOptions setAttributePOptions = attributeOptionsBuilder.build();
FileOutStream os = mFileSystem.createFile(uri, CreateFilePOptions.newBuilder().setMode(new alluxio.security.authorization.Mode((short) mode).toProto()).build());
long fid = mNextOpenFileId.getAndIncrement();
mOpenFiles.add(new OpenFileEntry(fid, path, null, os));
fi.fh.set(fid);
if (gid != GID || uid != UID) {
LOG.debug("Set attributes of path {} to {}", path, setAttributePOptions);
mFileSystem.setAttribute(uri, setAttributePOptions);
}
} catch (FileAlreadyExistsException e) {
LOG.debug("Failed to create {}, file already exists", path);
return -ErrorCodes.EEXIST();
} catch (InvalidPathException e) {
LOG.debug("Failed to create {}, path is invalid", path);
return -ErrorCodes.ENOENT();
} catch (Throwable t) {
LOG.error("Failed to create {}", path, t);
return AlluxioFuseUtils.getErrorCode(t);
}
return 0;
}
use of java.nio.file.InvalidPathException in project alluxio by Alluxio.
the class AlluxioFuseFileSystem method openInternal.
private int openInternal(String path, FuseFileInfo fi) {
final AlluxioURI uri = mPathResolverCache.getUnchecked(path);
// (see {@code man 2 open} for the structure of the flags bitfield)
// File creation flags are the last two bits of flags
final int flags = fi.flags.get();
if (mOpenFiles.size() >= MAX_OPEN_FILES) {
LOG.error("Cannot open {}: too many open files (MAX_OPEN_FILES: {})", path, MAX_OPEN_FILES);
return ErrorCodes.EMFILE();
}
FileInStream is;
try {
try {
is = mFileSystem.openFile(uri);
} catch (FileIncompleteException e) {
if (AlluxioFuseUtils.waitForFileCompleted(mFileSystem, uri)) {
is = mFileSystem.openFile(uri);
} else {
throw e;
}
}
} catch (OpenDirectoryException e) {
LOG.error("Cannot open folder {}", path);
return -ErrorCodes.EISDIR();
} catch (FileIncompleteException e) {
LOG.error("Cannot open incomplete file {}", path);
return -ErrorCodes.EFAULT();
} catch (FileDoesNotExistException | InvalidPathException e) {
LOG.error("Failed to open file {}, path does not exist or is invalid", path);
return -ErrorCodes.ENOENT();
} catch (Throwable t) {
LOG.error("Failed to open file {}", path, t);
return AlluxioFuseUtils.getErrorCode(t);
}
long fid = mNextOpenFileId.getAndIncrement();
mOpenFiles.add(new OpenFileEntry<>(fid, path, is, null));
fi.fh.set(fid);
return 0;
}
use of java.nio.file.InvalidPathException in project jboss-modules by jboss-modules.
the class PathResourceLoader method getResource.
@Override
public Resource getResource(final String name) {
final String cleanName = PathUtils.canonicalize(PathUtils.relativize(name));
final Path file;
try {
file = root.resolve(cleanName);
} catch (InvalidPathException ignored) {
return null;
}
if (!doPrivilegedIfNeeded(context, () -> Files.exists(file))) {
return null;
}
return new PathResource(file, cleanName, context);
}
use of java.nio.file.InvalidPathException in project jboss-modules by jboss-modules.
the class PathResourceLoader method getClassSpec.
@Override
public ClassSpec getClassSpec(final String fileName) throws IOException {
final Path file;
try {
file = root.resolve(fileName);
} catch (InvalidPathException ignored) {
return null;
}
return doPrivilegedIfNeeded(context, IOException.class, () -> {
if (!Files.exists(file)) {
return null;
}
final ClassSpec spec = new ClassSpec();
spec.setCodeSource(codeSource);
spec.setBytes(Files.readAllBytes(file));
return spec;
});
}
Aggregations