Package com.atlassian.bamboo.util
Class BambooFilenameUtils
java.lang.Object
com.atlassian.bamboo.util.BambooFilenameUtils
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
containsDirectoryTraversalString
(@Nullable String name) Basic validation of a String to see if it contains directory traversal chars.static boolean
Test if path "escapes" current directorystatic String
getShortWindowsPath
(String path) Returns a short 8.3 path for a given path.static boolean
isPathAbsolute
(String path) Test if path denotes absolute path.static @NotNull String
makeTempFileName
(@NotNull String prefix, @Nullable String suffix) Creates a temp file name in prefix + random number + suffix format.static @NotNull File
shortenNameIfPossible
(@NotNull File file) Shortens name to 8.3 on Windows on best effort basis.static @NotNull Path
shortenNameIfPossible
(@NotNull Path file) Shortens name to 8.3 on Windows on best effort basis.static @Nullable String
stripTrailingSlashes
(@Nullable String path) Strip trailing slashes from path
-
Method Details
-
isPathAbsolute
Test if path denotes absolute path. Method is platform specific. For Windows and Linux it will return different results.- Parameters:
path
- path to be verified- Returns:
- true if path is absolute
-
doesPathFollowToParentDirectory
Test if path "escapes" current directory- Parameters:
path
- path to be verified- Returns:
- true if path "escapes" current directory
-
getScriptSuffix
- Returns:
- script extension used on the current platform
-
getShortWindowsPath
Returns a short 8.3 path for a given path. If it's not possible, the parameter path is returned as is. Only converts the path on Windows. The input path has to exist. The method shells out to cmd, so you should cache the returned value. On systems other than Windows, it will only perform the existence check and just return the supplied path.- Parameters:
path
- path to convert to 8.3- Returns:
- converted path or an error message if the conversion was unsuccesful
- Throws:
IllegalArgumentException
- if the input path does not exist
-
shortenNameIfPossible
Shortens name to 8.3 on Windows on best effort basis. It will return the same name if shortening didn't work. -
shortenNameIfPossible
Shortens name to 8.3 on Windows on best effort basis. It will return the same name if shortening didn't work. -
makeTempFileName
@NotNull public static @NotNull String makeTempFileName(@NotNull @NotNull String prefix, @Nullable @Nullable String suffix) Creates a temp file name in prefix + random number + suffix format. If no suffix is given, ".tmp" will be used. -
stripTrailingSlashes
Strip trailing slashes from path -
containsDirectoryTraversalString
Basic validation of a String to see if it contains directory traversal chars. Prefer usingBambooFileUtils.newFileUnderParent(File, String)
but can use when that is not practical
-