Package com.atlassian.bamboo.utils
Class BambooFiles
java.lang.Object
com.atlassian.bamboo.utils.BambooFiles
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
static interface
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final boolean
static final org.apache.logging.log4j.Logger
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
applyReadOnlyPermissionsRecursively
(boolean isPosixFilesystem, Path path) Applies read-only permissions recursively to the files and directories for the supplied path.static void
static void
applyReadOnlyPermissionsTo
(boolean isPosixFilesystem, Path... canonicalFilePaths) Applies read only permissions to the files for the supplied file paths.static void
applyReadOnlyPermissionsTo
(Path... canonicalFilePaths) static BambooFiles.AutoRemoved
autoRemoved
(Path path) Wraps the suppliedPath
withAutoCloseable
.static Path
createTempDirectory
(Path dir, String prefix, FileAttribute<?>... attrs) static void
Deletes files, including readonly files on Windows.static void
deleteLogIfError
(Path path, org.apache.logging.log4j.Logger logger) Calldelete(Path)
and logs exception if happens.static boolean
deleteQuietly
(Path path) Deletes a path quietly, returns true on success.static Path
ensureEmptyDirExists
(Path dir) Removes content of the directory or creates new if it does not existstatic boolean
isExecutable
(Path path) static BambooFiles.QuietlyRemoved
quietlyRemoved
(Path path) Wraps the suppliedPath
withAutoCloseable
.static Path
resolvePathUnderParent
(@NotNull Path parent, @NotNull String child) Fulfills the general contract ofPath.resolve(String)
.static void
setAccessibleOnlyByOwner
(@NotNull Path path) Removes access toPath
from non-owners.static void
setExecutable
(Path path, boolean isExecutable) Sets executable bit onPath
static void
setReadOnly
(Path path, boolean isReadOnly) Sets readonly bit onPath
-
Field Details
-
log
public static final org.apache.logging.log4j.Logger log -
IS_POSIX_FILESYSTEM
public static final boolean IS_POSIX_FILESYSTEM
-
-
Constructor Details
-
BambooFiles
public BambooFiles()
-
-
Method Details
-
deleteQuietly
Deletes a path quietly, returns true on success. If the path is a non-empty directory, it does not get deleted. -
delete
Deletes files, including readonly files on Windows.- Throws:
IOException
-
deleteLogIfError
Calldelete(Path)
and logs exception if happens. -
isExecutable
- Throws:
IOException
-
autoRemoved
-
quietlyRemoved
Wraps the suppliedPath
withAutoCloseable
. The directory will be quietly deleted onAutoCloseable.close()
-
createTempDirectory
public static Path createTempDirectory(Path dir, String prefix, FileAttribute<?>... attrs) throws IOException SeeFiles.createTempDirectory(Path, String, FileAttribute[])
. This function will create the parent directories if they do not exist.- Throws:
IOException
-
setReadOnly
Sets readonly bit onPath
- Throws:
IOException
-
setExecutable
Sets executable bit onPath
- Throws:
IOException
-
setAccessibleOnlyByOwner
Removes access toPath
from non-owners. Note, for NTFS it removes all ACLs except owner. So if owner is not listed at ACLs then Path will become unavailable for Bamboo.- Throws:
IOException
-
resolvePathUnderParent
public static Path resolvePathUnderParent(@NotNull @NotNull Path parent, @NotNull @NotNull String child) Fulfills the general contract ofPath.resolve(String)
. The returned path is always in normalized and always rooted under the parent argument. Attempts to traverse out of the parent directory will result in IllegalArgumentException being thrown.- Parameters:
parent
- parent directorychild
- child under parent directory. Relative paths are allowed as long as the result is under the parent directory- Returns:
- a canonical child File rooted under parent directory
-
ensureEmptyDirExists
Removes content of the directory or creates new if it does not exist- Parameters:
dir
- folder to be cleaned or created- Returns:
- empty directory that refers to the same folder as the dir parameter
- Throws:
IOException
-
applyReadOnlyPermissionsTo
public static void applyReadOnlyPermissionsTo(boolean isPosixFilesystem, Path... canonicalFilePaths) Applies read only permissions to the files for the supplied file paths.- Parameters:
isPosixFilesystem
- A boolean stipulating if the current system is using a POSIX compliant filesystemcanonicalFilePaths
- An array of canonical file paths on which to apply the read only permission.
-
applyReadOnlyPermissionsRecursively
Applies read-only permissions recursively to the files and directories for the supplied path.- Parameters:
isPosixFilesystem
- A boolean stipulating if the current system is using a POSIX compliant filesystem.path
- The path on which to apply the read-only permission recursively.
-
applyReadOnlyPermissionsTo
-
applyReadOnlyPermissionsRecursively
-