@Override public boolean isAbsolute() { return delegate.isAbsolute(); }
public static boolean isAbsolutePath(String path) { return Paths.get(path).isAbsolute(); }
private static void validatePaths(@javax.annotation.Nullable Collection<Path> paths) { if (paths != null && paths.stream().anyMatch(p -> !p.isAbsolute())) { throw new IllegalStateException("SCM provider returned a changed file with a relative path but paths must be absolute. Please fix the provider."); } }
protected static File resolvePath(File baseDir, String path) { Path filePath = Paths.get(path); if (!filePath.isAbsolute()) { filePath = baseDir.toPath().resolve(path); } return filePath.normalize().toFile(); }
private Path toAbsoluteNormalizedPath(String potentiallyRelativePathStr) { Path filePath = Paths.get(potentiallyRelativePathStr); if (!filePath.isAbsolute()) { return Paths.get(root.toString(), filePath.toString()).normalize(); } else { return filePath.normalize(); } }
public static <T> T parseJson(Path path, Class<T> javaType) { if (!path.isAbsolute()) { path = path.toAbsolutePath(); } checkArgument(exists(path), "File does not exist: %s", path); checkArgument(isReadable(path), "File is not readable: %s", path); try { byte[] json = Files.readAllBytes(path); ObjectMapper mapper = new ObjectMapperProvider().get() .enable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); return mapper.readValue(json, javaType); } catch (IOException e) { throw new IllegalArgumentException(format("Invalid JSON file '%s' for '%s'", path, javaType), e); } } }
public AutoClosablePath(final Path path) { Preconditions.checkNotNull(path, "Path must not be null."); Preconditions.checkArgument(path.isAbsolute(), "Path must be absolute."); this.path = path; }
public Path metadataFilePath() { Optional<String> metadataFilePath = configuration.get(METADATA_FILE_PATH_KEY); if (metadataFilePath.isPresent()) { Path metadataPath = Paths.get(metadataFilePath.get()); if (!metadataPath.isAbsolute()) { throw MessageException.of(String.format("Property '%s' must point to an absolute path: %s", METADATA_FILE_PATH_KEY, metadataFilePath.get())); } return project.getBaseDir().resolve(metadataPath); } else { return project.getWorkDir().resolve(METADATA_DUMP_FILENAME); } }
/** * Get the file store type of a path. for example, /dev/sdd1(store name) /w2-gst-dev40d(mount * point) ext4(type) * * @return file store type */ public String getFileStoreType(final String path) { File diskFile = new File(path); if (!diskFile.exists()) { diskFile = diskFile.getParentFile(); } Path currentPath = diskFile.toPath(); if (currentPath.isAbsolute() && Files.exists(currentPath)) { try { FileStore store = Files.getFileStore(currentPath); return store.type(); } catch (IOException e) { return null; } } return null; }
if (f.getName().compareTo(filename.toString()) == 0) { File changedFile; if (filename.isAbsolute()) { changedFile = new File(filename.toString()); } else {
@Override public Iterator<Path> iterator() { return new LazyPathIterator( cloudPath.getFileSystem(), prefix, blobIterator, filter, dir.isAbsolute()); }
public void assertIsRelative(final AssertionInfo info, final Path actual) { assertNotNull(info, actual); if (actual.isAbsolute()) throw failures.failure(info, shouldBeRelativePath(actual)); }
public void assertIsAbsolute(final AssertionInfo info, final Path actual) { assertNotNull(info, actual); if (!actual.isAbsolute()) throw failures.failure(info, shouldBeAbsolutePath(actual)); }
/** * Creates a new instance of {@link AlluxioFuseFileSystem}. * * @param fs Alluxio file system * @param opts options * @param conf Alluxio configuration */ public AlluxioFuseFileSystem(FileSystem fs, AlluxioFuseOptions opts, AlluxioConfiguration conf) { super(); mFsName = conf.get(PropertyKey.FUSE_FS_NAME); mFileSystem = fs; mAlluxioRootPath = Paths.get(opts.getAlluxioRoot()); mNextOpenFileId = 0L; mOpenFiles = new IndexedSet<>(ID_INDEX, PATH_INDEX); final int maxCachedPaths = conf.getInt(PropertyKey.FUSE_CACHED_PATHS_MAX); mIsUserGroupTranslation = conf.getBoolean(PropertyKey.FUSE_USER_GROUP_TRANSLATION_ENABLED); mPathResolverCache = CacheBuilder.newBuilder() .maximumSize(maxCachedPaths) .build(new PathCacheLoader()); Preconditions.checkArgument(mAlluxioRootPath.isAbsolute(), "alluxio root path should be absolute"); }
public TempFolder provide(ScannerProperties scannerProps) { if (tempFolder == null) { String workingPathName = StringUtils.defaultIfBlank(scannerProps.property(CoreProperties.GLOBAL_WORKING_DIRECTORY), CoreProperties.GLOBAL_WORKING_DIRECTORY_DEFAULT_VALUE); Path workingPath = Paths.get(workingPathName); if (!workingPath.isAbsolute()) { Path home = findSonarHome(scannerProps); workingPath = home.resolve(workingPath).normalize(); } try { cleanTempFolders(workingPath); } catch (IOException e) { LOG.error(String.format("failed to clean global working directory: %s", workingPath), e); } Path tempDir = createTempFolder(workingPath); tempFolder = new DefaultTempFolder(tempDir.toFile(), true); } return tempFolder; }
public void assertIsRelative(final AssertionInfo info, final Path actual) { assertNotNull(info, actual); if (actual.isAbsolute()) throw failures.failure(info, shouldBeRelativePath(actual)); }
public void assertIsAbsolute(final AssertionInfo info, final Path actual) { assertNotNull(info, actual); if (!actual.isAbsolute()) throw failures.failure(info, shouldBeAbsolutePath(actual)); }
@Override protected WebResourceSet createMainResourceSet() { final Path docBase = config.docBase(); assert docBase.isAbsolute(); final String docBaseStr = docBase.toString(); getContext().setDocBase(docBaseStr); if (Files.isDirectory(docBase)) { return new DirResourceSet(this, "/", docBaseStr, "/"); } final Optional<String> jarRootOpt = config.jarRoot(); if (jarRootOpt.isPresent()) { // If docBase is a JAR file final String jarRoot = jarRootOpt.get(); if ("/".equals(jarRoot)) { return new JarResourceSet(this, "/", docBaseStr, "/"); } else { return new JarSubsetResourceSet(this, "/", docBaseStr, "/", jarRoot); } } throw new IllegalArgumentException(sm.getString("standardRoot.startInvalidMain", docBaseStr)); } }
/** * Checks that the given file can be deleted, throwing an exception if it can't. */ private void checkDeletable(File file, DeleteMode mode, Path path) throws IOException { if (file.isRootDirectory()) { throw new FileSystemException(path.toString(), null, "can't delete root directory"); } if (file.isDirectory()) { if (mode == DeleteMode.NON_DIRECTORY_ONLY) { throw new FileSystemException(path.toString(), null, "can't delete: is a directory"); } checkEmpty(((Directory) file), path); } else if (mode == DeleteMode.DIRECTORY_ONLY) { throw new FileSystemException(path.toString(), null, "can't delete: is not a directory"); } if (file == workingDirectory && !path.isAbsolute()) { // this is weird, but on Unix at least, the file system seems to be happy to delete the // working directory if you give the absolute path to it but fail if you use a relative path // that resolves to the working directory (e.g. "" or ".") throw new FileSystemException(path.toString(), null, "invalid argument"); } }
@Test public void testRelativityOfResolve() throws IOException { try (FileSystem fs = getTestBucket()) { Path abs1 = fs.getPath("/dir"); Path abs2 = abs1.resolve("subdir/"); Path rel1 = fs.getPath("dir"); Path rel2 = rel1.resolve("subdir/"); // children of absolute paths are absolute, // children of relative paths are relative. assertThat(abs1.isAbsolute()).isTrue(); assertThat(abs2.isAbsolute()).isTrue(); assertThat(rel1.isAbsolute()).isFalse(); assertThat(rel2.isAbsolute()).isFalse(); } }