Package com.facebook.buck.io.filesystem
Interface ProjectFilesystem
-
- All Known Implementing Classes:
DefaultProjectFilesystem
public interface ProjectFilesystem
An injectable service for interacting with the filesystem relative to the cell root.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Deprecated Methods Modifier and Type Method Description ProjectFilesystemView
asView()
Sha1HashCode
computeSha1(Path pathRelativeToProjectRootOrJustAbsolute)
String
computeSha256(Path pathRelativeToProjectRoot)
void
copy(Path source, Path target, CopySourceMode sourceMode)
void
copyFile(Path source, Path target)
void
copyFolder(Path source, Path target)
void
copyToOutputStream(Path pathRelativeToProjectRoot, OutputStream out)
Copies a file to an output stream.void
copyToPath(InputStream inputStream, Path pathRelativeToProjectRoot, CopyOption... options)
ProjectFilesystem
createBuckOutProjectFilesystem()
Path
createNewFile(Path pathRelativeToProjectRoot)
Creates a new file relative to the project root.void
createParentDirs(String pathRelativeToProjectRoot)
// @deprecated Prefer operating onPath
s directly, replaced bycreateParentDirs(java.nio.file.Path)
.void
createParentDirs(Path pathRelativeToProjectRoot)
default void
createSymLink(PathWrapper symLink, Path realFile, boolean force)
void
createSymLink(Path symLink, Path realFile, boolean force)
Path
createTempFile(String prefix, String suffix, FileAttribute<?>... attrs)
Returns a relative path whose parent directory is guaranteed to exist.Path
createTempFile(Path directory, String prefix, String suffix, FileAttribute<?>... attrs)
PrefercreateTempFile(String, String, FileAttribute[])
so that temporary files are guaranteed to be created underbuck-out
.void
deleteFileAtPath(Path pathRelativeToProjectRoot)
Deletes a file specified by its path relative to the project root.boolean
deleteFileAtPathIfExists(Path pathRelativeToProjectRoot)
Deletes a file specified by its path relative to the project root.void
deleteRecursivelyIfExists(Path pathRelativeToProjectRoot)
Recursively delete everything under the specified path.default boolean
exists(RelPath pathRelativeToProjectRoot, LinkOption... options)
default boolean
exists(ForwardRelativePath pathRelativeToProjectRoot, LinkOption... options)
boolean
exists(Path pathRelativeToProjectRoot, LinkOption... options)
com.google.common.collect.ImmutableSet<PathMatcher>
getBlacklistedPaths()
BuckPaths
getBuckPaths()
com.google.common.collect.ImmutableMap<String,? extends Object>
getDelegateDetails()
com.google.common.collect.ImmutableCollection<Path>
getDirectoryContents(Path pathToUse)
Deprecated.long
getFileAttributesForZipEntry(Path path)
getFileAttributesForZipEntry is similar to getPosixFileMode, but returns a number adjusted for use in zip files.long
getFileSize(Path pathRelativeToProjectRoot)
com.google.common.collect.ImmutableSet<Path>
getFilesUnderPath(Path pathRelativeToProjectRoot)
Deprecated.com.google.common.collect.ImmutableSet<Path>
getFilesUnderPath(Path pathRelativeToProjectRoot, java.util.function.Predicate<Path> predicate)
Deprecated.com.google.common.collect.ImmutableSet<Path>
getFilesUnderPath(Path pathRelativeToProjectRoot, java.util.function.Predicate<Path> predicate, EnumSet<FileVisitOption> visitOptions)
Deprecated.default FileSystem
getFileSystem()
com.google.common.collect.ImmutableSet<PathMatcher>
getIgnorePaths()
InputStream
getInputStreamForRelativePath(Path path)
// @deprecated Prefer operation onPath
s directly, replaced byFiles.newInputStream(java.nio.file.Path, java.nio.file.OpenOption...)
.Manifest
getJarManifest(Path path)
FileTime
getLastModifiedTime(Path pathRelativeToProjectRoot)
com.google.common.collect.ImmutableSortedSet<Path>
getMtimeSortedMatchingDirectoryContents(Path pathRelativeToProjectRoot, String globPattern)
Returns the files insidepathRelativeToProjectRoot
which matchglobPattern
, ordered in descending last modified time order.Path
getPath(String first, String... rest)
Converts a path string (or sequence of strings) to a Path with the same VFS as this instance.Path
getPathForRelativeExistingPath(Path pathRelativeToProjectRoot)
AsgetPathForRelativePath(java.nio.file.Path)
, but with the added twist that the existence of the path is checked before returning.Path
getPathForRelativePath(String pathRelativeToProjectRoot)
Path
getPathForRelativePath(Path pathRelativeToProjectRoot)
Optional<Path>
getPathRelativeToProjectRoot(Path path)
long
getPosixFileMode(Path path)
getPosixFileMode returns a number corresponding to stat()'s ST_MODE, for use when constructing tar archives.Set<PosixFilePermission>
getPosixFilePermissions(Path path)
Returns the set of POSIX file permissions, or the empty set if the underlying file system does not support POSIX file attributes.AbsPath
getRootPath()
default boolean
isDirectory(PathWrapper path, LinkOption... linkOptions)
boolean
isDirectory(Path child, LinkOption... linkOptions)
AllowsFiles.isDirectory(java.nio.file.Path, java.nio.file.LinkOption...)
to be faked in tests.boolean
isExecutable(Path child)
AllowsFiles.isExecutable(java.nio.file.Path)
to be faked in tests.default boolean
isFile(PathWrapper pathRelativeToProjectRoot, LinkOption... options)
boolean
isFile(Path pathRelativeToProjectRoot, LinkOption... options)
Checks whether there is a normal file at the specified path.boolean
isHidden(Path pathRelativeToProjectRoot)
boolean
isIgnored(RelPath path)
Deprecated.boolean
isSymLink(Path path)
Returns true if the file underpath
exists and is a symbolic link, false otherwise.void
mergeChildren(Path source, Path target, CopyOption... options)
Moves the children ofsource
intotarget
, merging the two directories.void
mkdirs(Path pathRelativeToProjectRoot)
Resolves the relative path against the project root and then callsFiles.createDirectories(java.nio.file.Path, java.nio.file.attribute.FileAttribute[])
void
move(Path source, Path target, CopyOption... options)
default InputStream
newFileInputStream(PathWrapper pathRelativeToProjectRoot)
InputStream
newFileInputStream(Path pathRelativeToProjectRoot)
OutputStream
newFileOutputStream(Path pathRelativeToProjectRoot, boolean append, FileAttribute<?>... attrs)
OutputStream
newFileOutputStream(Path pathRelativeToProjectRoot, FileAttribute<?>... attrs)
OutputStream
newUnbufferedFileOutputStream(Path pathRelativeToProjectRoot, boolean append, FileAttribute<?>... attrs)
<A extends BasicFileAttributes>
AreadAttributes(Path pathRelativeToProjectRoot, Class<A> type, LinkOption... options)
Optional<String>
readFileIfItExists(Path pathRelativeToProjectRoot)
Optional<String>
readFirstLine(String pathRelativeToProjectRoot)
Attempts to read the first line of the file specified by the relative path.Optional<String>
readFirstLine(Path pathRelativeToProjectRoot)
Attempts to read the first line of the file specified by the relative path.Optional<String>
readFirstLineFromFile(Path file)
Attempts to read the first line of the specified file.List<String>
readLines(Path pathRelativeToProjectRoot)
Properties
readPropertiesFile(Path propertiesFile)
Path
readSymLink(Path path)
Returns the target of the specified symbolic link.default RelPath
relativize(AbsPath path)
RelPath
relativize(Path path)
Construct a relative path between the project root and a given path.default AbsPath
resolve(RelPath path)
default Path
resolve(ForwardRelativePath path)
Path
resolve(String path)
Path
resolve(Path path)
Path
setLastModifiedTime(Path pathRelativeToProjectRoot, FileTime time)
Sets the last modified time for the given path.void
touch(Path fileToTouch)
void
walkFileTree(Path root, FileVisitor<Path> fileVisitor)
Deprecated.void
walkFileTree(Path root, Set<FileVisitOption> options, FileVisitor<Path> fileVisitor)
Deprecated.void
walkRelativeFileTree(Path pathRelativeToProjectRoot, FileVisitor<Path> fileVisitor)
Deprecated.void
walkRelativeFileTree(Path pathRelativeToProjectRoot, FileVisitor<Path> fileVisitor, boolean skipIgnored)
Deprecated.void
walkRelativeFileTree(Path pathRelativeToProjectRoot, EnumSet<FileVisitOption> visitOptions, FileVisitor<Path> fileVisitor, boolean skipIgnored)
Deprecated.void
writeBytesToPath(byte[] bytes, Path pathRelativeToProjectRoot, FileAttribute<?>... attrs)
void
writeContentsToPath(String contents, Path pathRelativeToProjectRoot, FileAttribute<?>... attrs)
void
writeLinesToPath(Iterable<String> lines, Path pathRelativeToProjectRoot, FileAttribute<?>... attrs)
Writes each line inlines
with a trailing newline to a file at the specified path.
-
-
-
Method Detail
-
asView
ProjectFilesystemView asView()
- Returns:
- the default view over this project filesystem, where the view root is the project root, and no ignored paths.
-
getRootPath
AbsPath getRootPath()
-
getFileSystem
default FileSystem getFileSystem()
-
createBuckOutProjectFilesystem
ProjectFilesystem createBuckOutProjectFilesystem()
-
getDelegateDetails
com.google.common.collect.ImmutableMap<String,? extends Object> getDelegateDetails()
- Returns:
- details about the delegate suitable for writing to a logger. It is recommended that the
keys of this map are unique in namespace of the things a logger may want to log. Values
must be
String
,int
, orboolean
.
-
resolve
Path resolve(Path path)
- Returns:
- the specified
path
resolved againstgetRootPath()
to an absolute path.
-
resolve
default Path resolve(ForwardRelativePath path)
- Returns:
- the specified
path
resolved againstgetRootPath()
to an absolute path.
-
resolve
default AbsPath resolve(RelPath path)
- Returns:
- the specified
path
resolved againstgetRootPath()
to an absolute path.
-
relativize
RelPath relativize(Path path)
Construct a relative path between the project root and a given path.
-
getBlacklistedPaths
com.google.common.collect.ImmutableSet<PathMatcher> getBlacklistedPaths()
- Returns:
- a set of
PathMatcher
objects ignored byisIgnored(RelPath)
-
getIgnorePaths
com.google.common.collect.ImmutableSet<PathMatcher> getIgnorePaths()
- Returns:
- A
ImmutableSet
ofPathMatcher
objects to have buck ignore.
-
getPathRelativeToProjectRoot
Optional<Path> getPathRelativeToProjectRoot(Path path)
- Parameters:
path
- Absolute path or path relative to the project root.- Returns:
- If
path
is relative, it is returned. If it is absolute and is inside the project root, it is relativized to the project root and returned. Otherwise an absent value is returned.
-
getPathForRelativeExistingPath
Path getPathForRelativeExistingPath(Path pathRelativeToProjectRoot)
AsgetPathForRelativePath(java.nio.file.Path)
, but with the added twist that the existence of the path is checked before returning.
-
exists
boolean exists(Path pathRelativeToProjectRoot, LinkOption... options)
-
exists
default boolean exists(ForwardRelativePath pathRelativeToProjectRoot, LinkOption... options)
-
exists
default boolean exists(RelPath pathRelativeToProjectRoot, LinkOption... options)
-
getFileSize
long getFileSize(Path pathRelativeToProjectRoot) throws IOException
- Throws:
IOException
-
deleteFileAtPathIfExists
boolean deleteFileAtPathIfExists(Path pathRelativeToProjectRoot) throws IOException
Deletes a file specified by its path relative to the project root.Ignores the failure if the file does not exist.
- Parameters:
pathRelativeToProjectRoot
- path to the file- Returns:
true
if the file was deleted,false
if it did not exist- Throws:
IOException
-
deleteFileAtPath
void deleteFileAtPath(Path pathRelativeToProjectRoot) throws IOException
Deletes a file specified by its path relative to the project root.- Parameters:
pathRelativeToProjectRoot
- path to the file- Throws:
IOException
-
readPropertiesFile
Properties readPropertiesFile(Path propertiesFile) throws IOException
- Throws:
IOException
-
isFile
boolean isFile(Path pathRelativeToProjectRoot, LinkOption... options)
Checks whether there is a normal file at the specified path.
-
isFile
default boolean isFile(PathWrapper pathRelativeToProjectRoot, LinkOption... options)
-
isHidden
boolean isHidden(Path pathRelativeToProjectRoot) throws IOException
- Throws:
IOException
-
walkRelativeFileTree
@Deprecated void walkRelativeFileTree(Path pathRelativeToProjectRoot, FileVisitor<Path> fileVisitor) throws IOException
Deprecated.Similar towalkFileTree(Path, FileVisitor)
except this takes in a path relative to the project root.This is deprecated. Please use
ProjectFilesystemView.walkRelativeFileTree(Path, EnumSet, FileVisitor)
instead.- Throws:
IOException
-
walkRelativeFileTree
@Deprecated void walkRelativeFileTree(Path pathRelativeToProjectRoot, FileVisitor<Path> fileVisitor, boolean skipIgnored) throws IOException
Deprecated.Similar towalkFileTree(Path, FileVisitor)
except this takes in a path relative to the project root.This is deprecated. Please use
ProjectFilesystemView.walkRelativeFileTree(Path, EnumSet, FileVisitor)
instead.- Throws:
IOException
-
walkRelativeFileTree
@Deprecated void walkRelativeFileTree(Path pathRelativeToProjectRoot, EnumSet<FileVisitOption> visitOptions, FileVisitor<Path> fileVisitor, boolean skipIgnored) throws IOException
Deprecated.Walks a project-root relative file tree with a visitor and visit options.This is deprecated. Please use
ProjectFilesystemView.walkRelativeFileTree(Path, EnumSet, FileVisitor)
instead.- Throws:
IOException
-
walkFileTree
@Deprecated void walkFileTree(Path root, FileVisitor<Path> fileVisitor) throws IOException
Deprecated.AllowsFiles.walkFileTree(java.nio.file.Path, java.util.Set<java.nio.file.FileVisitOption>, int, java.nio.file.FileVisitor<? super java.nio.file.Path>)
to be faked in tests.Use
ProjectFilesystemView.walkFileTree(Path, Set, FileVisitor)
instead.- Throws:
IOException
-
walkFileTree
@Deprecated void walkFileTree(Path root, Set<FileVisitOption> options, FileVisitor<Path> fileVisitor) throws IOException
Deprecated.- Throws:
IOException
-
getFilesUnderPath
@Deprecated com.google.common.collect.ImmutableSet<Path> getFilesUnderPath(Path pathRelativeToProjectRoot) throws IOException
Deprecated.- Throws:
IOException
-
getFilesUnderPath
@Deprecated com.google.common.collect.ImmutableSet<Path> getFilesUnderPath(Path pathRelativeToProjectRoot, java.util.function.Predicate<Path> predicate) throws IOException
Deprecated.UseProjectFilesystemView.getFilesUnderPath(Path, com.google.common.base.Predicate, EnumSet)
instead- Throws:
IOException
-
getFilesUnderPath
@Deprecated com.google.common.collect.ImmutableSet<Path> getFilesUnderPath(Path pathRelativeToProjectRoot, java.util.function.Predicate<Path> predicate, EnumSet<FileVisitOption> visitOptions) throws IOException
Deprecated.UseProjectFilesystemView.getFilesUnderPath(Path, com.google.common.base.Predicate, EnumSet)
instead- Throws:
IOException
-
isDirectory
boolean isDirectory(Path child, LinkOption... linkOptions)
AllowsFiles.isDirectory(java.nio.file.Path, java.nio.file.LinkOption...)
to be faked in tests.
-
isDirectory
default boolean isDirectory(PathWrapper path, LinkOption... linkOptions)
-
isExecutable
boolean isExecutable(Path child)
AllowsFiles.isExecutable(java.nio.file.Path)
to be faked in tests.
-
getDirectoryContents
@Deprecated com.google.common.collect.ImmutableCollection<Path> getDirectoryContents(Path pathToUse) throws IOException
Deprecated.UseProjectFilesystemView.getDirectoryContents(Path)
instead- Throws:
IOException
-
getMtimeSortedMatchingDirectoryContents
com.google.common.collect.ImmutableSortedSet<Path> getMtimeSortedMatchingDirectoryContents(Path pathRelativeToProjectRoot, String globPattern) throws IOException
Returns the files insidepathRelativeToProjectRoot
which matchglobPattern
, ordered in descending last modified time order. This will not obey the results ofisIgnored(RelPath)
.- Throws:
IOException
-
getLastModifiedTime
FileTime getLastModifiedTime(Path pathRelativeToProjectRoot) throws IOException
- Throws:
IOException
-
setLastModifiedTime
Path setLastModifiedTime(Path pathRelativeToProjectRoot, FileTime time) throws IOException
Sets the last modified time for the given path.- Throws:
IOException
-
deleteRecursivelyIfExists
void deleteRecursivelyIfExists(Path pathRelativeToProjectRoot) throws IOException
Recursively delete everything under the specified path. Ignore the failure if the file at the specified path does not exist.- Throws:
IOException
-
mkdirs
void mkdirs(Path pathRelativeToProjectRoot) throws IOException
Resolves the relative path against the project root and then callsFiles.createDirectories(java.nio.file.Path, java.nio.file.attribute.FileAttribute[])
- Throws:
IOException
-
createNewFile
Path createNewFile(Path pathRelativeToProjectRoot) throws IOException
Creates a new file relative to the project root.- Throws:
IOException
-
createParentDirs
void createParentDirs(String pathRelativeToProjectRoot) throws IOException
// @deprecated Prefer operating onPath
s directly, replaced bycreateParentDirs(java.nio.file.Path)
.- Throws:
IOException
-
createParentDirs
void createParentDirs(Path pathRelativeToProjectRoot) throws IOException
- Parameters:
pathRelativeToProjectRoot
- Must identify a file, not a directory. (Unfortunately, we have no way to assert this because the path is not expected to exist yet.)- Throws:
IOException
-
writeLinesToPath
void writeLinesToPath(Iterable<String> lines, Path pathRelativeToProjectRoot, FileAttribute<?>... attrs) throws IOException
Writes each line inlines
with a trailing newline to a file at the specified path.The parent path of
pathRelativeToProjectRoot
must exist.- Throws:
IOException
-
writeContentsToPath
void writeContentsToPath(String contents, Path pathRelativeToProjectRoot, FileAttribute<?>... attrs) throws IOException
- Throws:
IOException
-
writeBytesToPath
void writeBytesToPath(byte[] bytes, Path pathRelativeToProjectRoot, FileAttribute<?>... attrs) throws IOException
- Throws:
IOException
-
newFileOutputStream
OutputStream newFileOutputStream(Path pathRelativeToProjectRoot, FileAttribute<?>... attrs) throws IOException
- Throws:
IOException
-
newFileOutputStream
OutputStream newFileOutputStream(Path pathRelativeToProjectRoot, boolean append, FileAttribute<?>... attrs) throws IOException
- Throws:
IOException
-
newUnbufferedFileOutputStream
OutputStream newUnbufferedFileOutputStream(Path pathRelativeToProjectRoot, boolean append, FileAttribute<?>... attrs) throws IOException
- Throws:
IOException
-
readAttributes
<A extends BasicFileAttributes> A readAttributes(Path pathRelativeToProjectRoot, Class<A> type, LinkOption... options) throws IOException
- Throws:
IOException
-
newFileInputStream
InputStream newFileInputStream(Path pathRelativeToProjectRoot) throws IOException
- Throws:
IOException
-
newFileInputStream
default InputStream newFileInputStream(PathWrapper pathRelativeToProjectRoot) throws IOException
- Throws:
IOException
-
copyToPath
void copyToPath(InputStream inputStream, Path pathRelativeToProjectRoot, CopyOption... options) throws IOException
- Parameters:
inputStream
- Source of the bytes. This method does not close this stream.- Throws:
IOException
-
copyToOutputStream
void copyToOutputStream(Path pathRelativeToProjectRoot, OutputStream out) throws IOException
Copies a file to an output stream.- Throws:
IOException
-
readFirstLine
Optional<String> readFirstLine(String pathRelativeToProjectRoot)
Attempts to read the first line of the file specified by the relative path. If the file does not exist, is empty, or encounters an error while being read,Optional.empty()
is returned. Otherwise, anOptional
with the first line of the file will be returned.// @deprecated PRefero operation on
Path
s directly, replaced byreadFirstLine(java.nio.file.Path)
-
readFirstLine
Optional<String> readFirstLine(Path pathRelativeToProjectRoot)
Attempts to read the first line of the file specified by the relative path. If the file does not exist, is empty, or encounters an error while being read,Optional.empty()
is returned. Otherwise, anOptional
with the first line of the file will be returned.
-
readFirstLineFromFile
Optional<String> readFirstLineFromFile(Path file)
Attempts to read the first line of the specified file. If the file does not exist, is empty, or encounters an error while being read,Optional.empty()
is returned. Otherwise, anOptional
with the first line of the file will be returned.
-
readLines
List<String> readLines(Path pathRelativeToProjectRoot) throws IOException
- Throws:
IOException
-
getInputStreamForRelativePath
InputStream getInputStreamForRelativePath(Path path) throws IOException
// @deprecated Prefer operation onPath
s directly, replaced byFiles.newInputStream(java.nio.file.Path, java.nio.file.OpenOption...)
.- Throws:
IOException
-
computeSha1
Sha1HashCode computeSha1(Path pathRelativeToProjectRootOrJustAbsolute) throws IOException
- Throws:
IOException
-
computeSha256
String computeSha256(Path pathRelativeToProjectRoot) throws IOException
- Throws:
IOException
-
copy
void copy(Path source, Path target, CopySourceMode sourceMode) throws IOException
- Throws:
IOException
-
move
void move(Path source, Path target, CopyOption... options) throws IOException
- Throws:
IOException
-
mergeChildren
void mergeChildren(Path source, Path target, CopyOption... options) throws IOException
Moves the children ofsource
intotarget
, merging the two directories.- Throws:
IOException
-
copyFolder
void copyFolder(Path source, Path target) throws IOException
- Throws:
IOException
-
copyFile
void copyFile(Path source, Path target) throws IOException
- Throws:
IOException
-
createSymLink
void createSymLink(Path symLink, Path realFile, boolean force) throws IOException
- Throws:
IOException
-
createSymLink
default void createSymLink(PathWrapper symLink, Path realFile, boolean force) throws IOException
- Throws:
IOException
-
getPosixFilePermissions
Set<PosixFilePermission> getPosixFilePermissions(Path path) throws IOException
Returns the set of POSIX file permissions, or the empty set if the underlying file system does not support POSIX file attributes.- Throws:
IOException
-
isSymLink
boolean isSymLink(Path path)
Returns true if the file underpath
exists and is a symbolic link, false otherwise.
-
readSymLink
Path readSymLink(Path path) throws IOException
Returns the target of the specified symbolic link.- Throws:
IOException
-
getJarManifest
Manifest getJarManifest(Path path) throws IOException
- Throws:
IOException
-
getPosixFileMode
long getPosixFileMode(Path path) throws IOException
getPosixFileMode returns a number corresponding to stat()'s ST_MODE, for use when constructing tar archives.- Throws:
IOException
-
getFileAttributesForZipEntry
long getFileAttributesForZipEntry(Path path) throws IOException
getFileAttributesForZipEntry is similar to getPosixFileMode, but returns a number adjusted for use in zip files.- Throws:
IOException
-
getBuckPaths
BuckPaths getBuckPaths()
-
isIgnored
@Deprecated boolean isIgnored(RelPath path)
Deprecated.UseProjectFilesystemView.isIgnored(Path)
instead- Parameters:
path
- the path to check.- Returns:
- whether ignoredPaths contains path or any of its ancestors.
-
createTempFile
Path createTempFile(String prefix, String suffix, FileAttribute<?>... attrs) throws IOException
Returns a relative path whose parent directory is guaranteed to exist. The path will be underbuck-out
, so it is safe to write to.- Throws:
IOException
-
createTempFile
Path createTempFile(Path directory, String prefix, String suffix, FileAttribute<?>... attrs) throws IOException
PrefercreateTempFile(String, String, FileAttribute[])
so that temporary files are guaranteed to be created underbuck-out
. This method will be deprecated once t12079608 is resolved.- Throws:
IOException
-
touch
void touch(Path fileToTouch) throws IOException
- Throws:
IOException
-
getPath
Path getPath(String first, String... rest)
Converts a path string (or sequence of strings) to a Path with the same VFS as this instance.- See Also:
FileSystem.getPath(String, String...)
-
-