Xgit v0.1.6 Xgit.Core.ValidatePath View Source
Verifies that a path is an acceptable part of a tree structure.
Link to this section Summary
Types
Error codes which can be returned by check_path/2
.
Error codes which can be returned by check_path_segment/2
.
Functions
Check the provided path to see if it is a valid path within a git repository.
Check the provided path segment to see if it is a valid path within a git tree
object.
Return true
if the filename could be read as a .gitmodules
file when
checked out to the working directory.
Link to this section Types
check_path_reason()
View Sourcecheck_path_reason() :: :invalid_name | :empty_path | :absolute_path | :duplicate_slash | :trailing_slash
Error codes which can be returned by check_path/2
.
check_path_segment_reason()
View Sourcecheck_path_segment_reason() :: :invalid_name | :empty_name | :reserved_name | :invalid_utf8_sequence | :invalid_name_on_windows | :windows_device_name
Error codes which can be returned by check_path_segment/2
.
Link to this section Functions
check_path(path, opts \\ [])
View Sourcecheck_path(path :: [byte()], windows?: boolean(), macosx?: boolean()) :: :ok | {:error, check_path_reason()} | {:error, check_path_segment_reason()}
Check the provided path to see if it is a valid path within a git repository.
The rules enforced here are slightly different from what is allowed in a tree
object in that we allow /
characters to build hierarchical paths.
Parameters
path
is a UTF-8 byte list containing the path to be tested.
Options
windows?
:true
to additionally verify that the path is permissible on Windows file systemsmacosx?
:true
to additionally verify that the path is permissible on Mac OS X file systems
Return Values
:ok
if the name is permissible given the constraints chosen above{:error, :invalid_name}
if the name is not permissible{:error, :empty_path}
if the name is empty{:error, :absolute_path}
if the name starts with a/
{:error, :duplicate_slash}
if the name contains two/
characters in a row{:error, :trailing_slash}
if the name contains a trailing/
See also: error return values from check_path_segment/2
.
check_path_segment(path, opts \\ [])
View Sourcecheck_path_segment(path :: [byte()], windows?: boolean(), macosx?: boolean()) :: :ok | {:error, check_path_segment_reason()}
Check the provided path segment to see if it is a valid path within a git tree
object.
Parameters
path
is a UTF-8 byte list containing the path segment to be tested.
Options
windows?
:true
to additionally verify that the path is permissible on Windows file systemsmacosx?
:true
to additionally verify that the path is permissible on Mac OS X file systems
Return Values
:ok
if the name is permissible given the constraints chosen above{:error, :invalid_name}
if the name is not permissible{:error, :empty_name}
if the name is empty{:error, :reserved_name}
if the name is reserved for git's use (i.e..git
){:error, :invalid_utf8_sequence}
if the name contains certain incomplete UTF-8 byte sequences (only whenmacosx?: true
is selected){:error, :invalid_name_on_windows}
if the name contains characters that are not allowed on Windows file systems (only whenwindows?: true
is selected){:error, :windows_device_name}
if the name matches a Windows device name (aux
, etc.) (only whenwindows?: true
is selected)
Return true
if the filename could be read as a .gitmodules
file when
checked out to the working directory.
This would seem like a simple comparison, but some filesystems have peculiar rules for normalizing filenames:
NTFS has backward-compatibility support for 8.3 synonyms of long file names. (See https://web.archive.org/web/20160318181041/https://usn.pw/blog/gen/2015/06/09/filenames/ for details.) NTFS is also case-insensitive.
MacOS's HFS+ folds away ignorable Unicode characters in addition to case folding.
Parameters
path
is a UTF-8 byte list containing the path to be tested.
Options
By default, this function will only check for the plain .gitmodules
name.
windows?
:true
to additionally check for any path that might be treated as a.gitmodules
file on Windows file systemsmacosx?
:true
to additionally check for any path that might be treated as a.gitmodules
file on Mac OS X file systems