Package com.atlassian.bamboo.utils
Class BambooFiles
- java.lang.Object
-
- com.atlassian.bamboo.utils.BambooFiles
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceBambooFiles.AutoRemovedstatic interfaceBambooFiles.QuietlyRemoved
-
Field Summary
Fields Modifier and Type Field Description static org.apache.log4j.Loggerlog
-
Constructor Summary
Constructors Constructor Description BambooFiles()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static BambooFiles.AutoRemovedautoRemoved(Path path)Wraps the suppliedPathwithAutoCloseable.static PathcreateTempDirectory(Path dir, String prefix, FileAttribute<?>... attrs)static voiddelete(Path path)Deletes files, including readonly files on Windows.static voiddeleteLogIfError(Path path, org.apache.log4j.Logger logger)Calldelete(Path)and logs exception if happens.static booleandeleteQuietly(Path path)Deletes a path quietly, returns true on success.static booleanisExecutable(Path path)static BambooFiles.QuietlyRemovedquietlyRemoved(Path path)Wraps the suppliedPathwithAutoCloseable.static PathresolvePathUnderParent(@NotNull Path parent, @NotNull String child)Fulfills the general contract ofPath.resolve(String).static voidsetAccessibleOnlyByOwner(@NotNull Path path)Removes access toPathfrom non-owners.static voidsetExecutable(Path path, boolean isExecutable)Sets executable bit onPathstatic voidsetReadOnly(Path path, boolean isReadOnly)Sets readonly bit onPath
-
-
-
Method Detail
-
deleteQuietly
public static boolean deleteQuietly(Path path)
Deletes a path quietly, returns true on success. If the path is a non-empty directory, it does not get deleted.
-
delete
public static void delete(Path path) throws IOException
Deletes files, including readonly files on Windows.- Throws:
IOException
-
deleteLogIfError
public static void deleteLogIfError(Path path, org.apache.log4j.Logger logger)
Calldelete(Path)and logs exception if happens.
-
isExecutable
public static boolean isExecutable(Path path) throws IOException
- Throws:
IOException
-
autoRemoved
public static BambooFiles.AutoRemoved autoRemoved(Path path)
-
quietlyRemoved
public static BambooFiles.QuietlyRemoved quietlyRemoved(Path path)
Wraps the suppliedPathwithAutoCloseable. 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
public static void setReadOnly(Path path, boolean isReadOnly) throws IOException
Sets readonly bit onPath- Throws:
IOException
-
setExecutable
public static void setExecutable(Path path, boolean isExecutable) throws IOException
Sets executable bit onPath- Throws:
IOException
-
setAccessibleOnlyByOwner
public static void setAccessibleOnlyByOwner(@NotNull @NotNull Path path) throws IOExceptionRemoves access toPathfrom 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
-
-