CreateTempDir will create a temporary directory in baseDir
with CSPRNG entropy in the name to avoid clashes and mitigate
directory traversal. If baseDir is empty string, os.TempDir()
will be used. It is the caller's responsibility to remove the
directory after use. Will return the full path of the generated
directory.
Inbound will validate if the given candidate path is inside the
baseDir. This is useful to make sure that malicious candidates
are not targeting a file outside of baseDir boundaries.
Considerations:
- baseDir must be absolute path. Will return false otherwise
- candidate can be absolute or relative path
- candidate should not be symlink as only syntatic validation is
applied by this function
RelativePath will remove the basePath string from the fullPath
including the path separator. Differently from filepath.Rel, this
function will return error (RelativeOutOfBoundErr) if basePath
does not match (example 2).
Tgz will iterate over all files found in srcPath compressing them with gzip
and archiving with Tar. Will invoke every given writer while generating the tgz.
This is useful to generate checksums. Will exclude files matching the exclusions
list blob.