use of java.nio.file.InvalidPathException in project alluxio by Alluxio.
the class AlluxioJniFuseFileSystem method getattrInternal.
private int getattrInternal(String path, FileStat stat) {
final AlluxioURI uri = mPathResolverCache.getUnchecked(path);
try {
URIStatus status = null;
// Handle special metadata cache operation
if (mConf.getBoolean(PropertyKey.FUSE_SPECIAL_COMMAND_ENABLED) && mFuseShell.isSpecialCommand(uri)) {
// TODO(lu) add cache for isFuseSpecialCommand if needed
status = mFuseShell.runCommand(uri);
} else {
status = mFileSystem.getStatus(uri);
}
long size = status.getLength();
if (!status.isCompleted()) {
if (mCreateFileEntries.contains(PATH_INDEX, path)) {
// Alluxio master will not update file length until file is completed
// get file length from the current output stream
CreateFileEntry<FileOutStream> ce = mCreateFileEntries.getFirstByField(PATH_INDEX, path);
if (ce != null) {
FileOutStream os = ce.getOut();
size = os.getBytesWritten();
}
} else if (!AlluxioFuseUtils.waitForFileCompleted(mFileSystem, uri)) {
// Always block waiting for file to be completed except when the file is writing
// We do not want to block the writing process
LOG.error("File {} is not completed", path);
} else {
// Update the file status after waiting
status = mFileSystem.getStatus(uri);
size = status.getLength();
}
}
stat.st_size.set(size);
// Sets block number to fulfill du command needs
// `st_blksize` is ignored in `getattr` according to
// https://github.com/libfuse/libfuse/blob/d4a7ba44b022e3b63fc215374d87ed9e930d9974/include/fuse.h#L302
// According to http://man7.org/linux/man-pages/man2/stat.2.html,
// `st_blocks` is the number of 512B blocks allocated
stat.st_blocks.set((int) Math.ceil((double) size / 512));
final long ctime_sec = status.getLastModificationTimeMs() / 1000;
final long atime_sec = status.getLastAccessTimeMs() / 1000;
// Keeps only the "residual" nanoseconds not caputred in citme_sec
final long ctime_nsec = (status.getLastModificationTimeMs() % 1000) * 1_000_000L;
final long atime_nsec = (status.getLastAccessTimeMs() % 1000) * 1_000_000L;
stat.st_atim.tv_sec.set(atime_sec);
stat.st_atim.tv_nsec.set(atime_nsec);
stat.st_ctim.tv_sec.set(ctime_sec);
stat.st_ctim.tv_nsec.set(ctime_nsec);
stat.st_mtim.tv_sec.set(ctime_sec);
stat.st_mtim.tv_nsec.set(ctime_nsec);
if (mIsUserGroupTranslation) {
// Translate the file owner/group to unix uid/gid
// Show as uid==-1 (nobody) if owner does not exist in unix
// Show as gid==-1 (nogroup) if group does not exist in unix
stat.st_uid.set(mUidCache.get(status.getOwner()));
stat.st_gid.set(mGidCache.get(status.getGroup()));
} else {
stat.st_uid.set(AlluxioFuseUtils.DEFAULT_UID);
stat.st_gid.set(AlluxioFuseUtils.DEFAULT_GID);
}
int mode = status.getMode();
if (status.isFolder()) {
mode |= FileStat.S_IFDIR;
} else {
mode |= FileStat.S_IFREG;
}
stat.st_mode.set(mode);
stat.st_nlink.set(1);
} catch (FileDoesNotExistException | InvalidPathException e) {
LOG.debug("Failed to get info of {}, path does not exist or is invalid", path);
return -ErrorCodes.ENOENT();
} catch (AccessControlException e) {
LOG.error("Permission denied when getattr {}: ", path, e);
return -ErrorCodes.EACCES();
} catch (Throwable e) {
LOG.error("Failed to getattr {}: ", path, e);
return -ErrorCodes.EIO();
}
return 0;
}
use of java.nio.file.InvalidPathException in project alluxio by Alluxio.
the class AlluxioFuseFileSystem method getattrInternal.
private int getattrInternal(String path, FileStat stat) {
final AlluxioURI turi = mPathResolverCache.getUnchecked(path);
try {
URIStatus status = mFileSystem.getStatus(turi);
if (!status.isCompleted()) {
// We do not want to block the writing process
if (!mOpenFiles.contains(PATH_INDEX, path) && !AlluxioFuseUtils.waitForFileCompleted(mFileSystem, turi)) {
LOG.error("File {} is not completed", path);
}
status = mFileSystem.getStatus(turi);
}
long size = status.getLength();
stat.st_size.set(size);
// Sets block number to fulfill du command needs
// `st_blksize` is ignored in `getattr` according to
// https://github.com/libfuse/libfuse/blob/d4a7ba44b022e3b63fc215374d87ed9e930d9974/include/fuse.h#L302
// According to http://man7.org/linux/man-pages/man2/stat.2.html,
// `st_blocks` is the number of 512B blocks allocated
stat.st_blocks.set((int) Math.ceil((double) size / 512));
final long ctime_sec = status.getLastModificationTimeMs() / 1000;
// Keeps only the "residual" nanoseconds not caputred in citme_sec
final long ctime_nsec = (status.getLastModificationTimeMs() % 1000) * 1000;
stat.st_ctim.tv_sec.set(ctime_sec);
stat.st_ctim.tv_nsec.set(ctime_nsec);
stat.st_mtim.tv_sec.set(ctime_sec);
stat.st_mtim.tv_nsec.set(ctime_nsec);
if (mIsUserGroupTranslation) {
// Translate the file owner/group to unix uid/gid
// Show as uid==-1 (nobody) if owner does not exist in unix
// Show as gid==-1 (nogroup) if group does not exist in unix
stat.st_uid.set(AlluxioFuseUtils.getUid(status.getOwner()));
stat.st_gid.set(AlluxioFuseUtils.getGidFromGroupName(status.getGroup()));
} else {
stat.st_uid.set(UID);
stat.st_gid.set(GID);
}
int mode = status.getMode();
if (status.isFolder()) {
mode |= FileStat.S_IFDIR;
} else {
mode |= FileStat.S_IFREG;
}
stat.st_mode.set(mode);
stat.st_nlink.set(1);
} catch (FileDoesNotExistException | InvalidPathException e) {
LOG.debug("Failed to get info of {}, path does not exist or is invalid", path);
return -ErrorCodes.ENOENT();
} catch (Throwable t) {
LOG.error("Failed to get info of {}", path, t);
return AlluxioFuseUtils.getErrorCode(t);
}
return 0;
}
use of java.nio.file.InvalidPathException in project es6draft by anba.
the class NodeModuleResolution method resolve.
/**
* Resolves a module name.
*
* @param baseDirectory
* the base directory
* @param normalizedName
* the normalized module identifier
* @param unnormalizedName
* the unnormalized module identifier
* @param referrerId
* the referrer module identifier or {@code null}
* @return the resolved and normalized module identifier
* @throws MalformedNameException
* if the name cannot be normalized
*/
static FileSourceIdentifier resolve(Path baseDirectory, FileSourceIdentifier normalizedName, String unnormalizedName, SourceIdentifier referrerId) throws MalformedNameException {
if (referrerId != null) {
try {
Path unnormalizedPath = Paths.get(unnormalizedName);
Path referrer = Paths.get(baseDirectory.toUri().resolve(referrerId.toUri()));
if (unnormalizedName.startsWith("./") || unnormalizedName.startsWith("../")) {
Path path = referrer.resolveSibling(unnormalizedPath);
Path file = loadAsFile(path);
if (file != null) {
return new FileSourceIdentifier(file);
}
file = loadAsDirectory(path);
if (file != null) {
return new FileSourceIdentifier(file);
}
}
Path file = loadNodeModules(unnormalizedPath, referrer, baseDirectory);
if (file != null) {
return new FileSourceIdentifier(file);
}
} catch (InvalidPathException e) {
throw new MalformedNameException(unnormalizedName);
}
}
// If node module resolution failed, use default module name resolution.
return normalizedName;
}
use of java.nio.file.InvalidPathException in project elasticsearch by elastic.
the class TranslogTests method randomNonTranslogPatternString.
private String randomNonTranslogPatternString(int min, int max) {
String string;
boolean validPathString;
do {
validPathString = false;
string = randomRealisticUnicodeOfCodepointLength(randomIntBetween(min, max));
try {
final Path resolved = translogDir.resolve(string);
// some strings (like '/' , '..') do not refer to a file, which we this method should return
validPathString = resolved.getFileName() != null;
} catch (InvalidPathException ex) {
// some FS don't like our random file names -- let's just skip these random choices
}
} while (Translog.PARSE_STRICT_ID_PATTERN.matcher(string).matches() || validPathString == false);
return string;
}
use of java.nio.file.InvalidPathException in project jetty.project by eclipse.
the class FileSystemResourceTest method testNTFSFileDataStreamAlias.
/**
* NTFS Alternative Data / File Streams.
* <p>
* See: http://msdn.microsoft.com/en-us/library/windows/desktop/aa364404(v=vs.85).aspx
* @throws Exception failed test
*/
@Test
public void testNTFSFileDataStreamAlias() throws Exception {
Path dir = testdir.getPath().normalize().toRealPath();
Files.createDirectories(dir);
Path path = dir.resolve("testfile");
Files.createFile(path);
try (Resource base = newResource(dir.toFile())) {
Resource resource = base.addPath("testfile");
assertThat("resource.alias", resource, hasNoAlias());
assertThat("resource.uri.alias", newResource(resource.getURI()), hasNoAlias());
assertThat("resource.file.alias", newResource(resource.getFile()), hasNoAlias());
try {
// Attempt to reference same file, but via NTFS DATA stream
Resource alias = base.addPath("testfile::$DATA");
if (alias.exists()) {
assumeThat(alias.getURI().getScheme(), is("http"));
// If it exists, it must be an alias
assertThat("resource.alias", alias, isAliasFor(resource));
assertThat("resource.uri.alias", newResource(alias.getURI()), isAliasFor(resource));
assertThat("resource.file.alias", newResource(alias.getFile()), isAliasFor(resource));
}
} catch (InvalidPathException e) {
// NTFS filesystem streams are unsupported on some platforms.
assumeNoException(e);
}
}
}
Aggregations