Package org.apache.solr.util
Class FileUtils
java.lang.Object
org.apache.solr.util.FileUtils
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic PathcreateDirectories(Path path) static booleanfileExists(String filePathString) static booleanisPathAChildOfParent(Path parent, Path potentialChild) Checks whether a child path falls under a particular parentstatic StringTakes a path and normalizes it with the OS default filesystems separator
-
Constructor Details
-
FileUtils
public FileUtils()
-
-
Method Details
-
fileExists
-
createDirectories
- Throws:
IOException
-
isPathAChildOfParent
Checks whether a child path falls under a particular parentUseful for validating user-provided relative paths, which generally aren't expected to "escape" a given parent/root directory. Parent and child paths are "normalized" by
Path.normalize(). This removes explicit backtracking (e.g. "../") though it will not resolve symlinks if any are present in the provided Paths, so some forms of parent "escape" remain undetected. Paths needn't exist as a file or directory for comparison purposes.Note, this method does not consult the file system
- Parameters:
parent- the path of a 'parent' node. Path must be syntactically valid but needn't exist.potentialChild- the path of a potential child. Typically obtained via: parent.resolve(relativeChildPath). Path must be syntactically valid but needn't exist.- Returns:
- true if 'potentialChild' nests under the provided 'parent', false otherwise.
-
normalizeToOsPathSeparator
Takes a path and normalizes it with the OS default filesystems separator- Parameters:
path- the path to normalize- Returns:
- path normalized with the filesystems default separator
-