Commit 1728e27c by Edward Thomson

path: length validation respecting core.longpaths

Teach `git_path_is_valid` to respect `core.longpaths`.  Add helper
methods to validate length and set the error message appropriately.
parent 315a43b2
...@@ -285,6 +285,28 @@ GIT_INLINE(unsigned int) dotgit_flags( ...@@ -285,6 +285,28 @@ GIT_INLINE(unsigned int) dotgit_flags(
return flags; return flags;
} }
GIT_INLINE(unsigned int) length_flags(
git_repository *repo,
unsigned int flags)
{
#ifdef GIT_WIN32
int allow = 0;
if (repo &&
git_repository__configmap_lookup(&allow, repo, GIT_CONFIGMAP_LONGPATHS) < 0)
allow = 0;
if (allow)
flags &= ~GIT_FS_PATH_REJECT_LONG_PATHS;
#else
GIT_UNUSED(repo);
flags &= ~GIT_FS_PATH_REJECT_LONG_PATHS;
#endif
return flags;
}
bool git_path_str_is_valid( bool git_path_str_is_valid(
git_repository *repo, git_repository *repo,
const git_str *path, const git_str *path,
...@@ -297,6 +319,10 @@ bool git_path_str_is_valid( ...@@ -297,6 +319,10 @@ bool git_path_str_is_valid(
if ((flags & GIT_PATH_REJECT_DOT_GIT)) if ((flags & GIT_PATH_REJECT_DOT_GIT))
flags = dotgit_flags(repo, flags); flags = dotgit_flags(repo, flags);
/* Update the length checks based on platform */
if ((flags & GIT_FS_PATH_REJECT_LONG_PATHS))
flags = length_flags(repo, flags);
data.repo = repo; data.repo = repo;
data.file_mode = file_mode; data.file_mode = file_mode;
data.flags = flags; data.flags = flags;
......
...@@ -41,4 +41,28 @@ GIT_INLINE(bool) git_path_is_valid( ...@@ -41,4 +41,28 @@ GIT_INLINE(bool) git_path_is_valid(
return git_path_str_is_valid(repo, &str, file_mode, flags); return git_path_str_is_valid(repo, &str, file_mode, flags);
} }
GIT_INLINE(int) git_path_validate_str_length(
git_repository *repo,
const git_str *path)
{
if (!git_path_str_is_valid(repo, path, 0, GIT_FS_PATH_REJECT_LONG_PATHS)) {
if (path->size == SIZE_MAX)
git_error_set(GIT_ERROR_FILESYSTEM, "path too long: '%s'", path->ptr);
else
git_error_set(GIT_ERROR_FILESYSTEM, "path too long: '%.*s'", (int)path->size, path->ptr);
return -1;
}
return 0;
}
GIT_INLINE(int) git_path_validate_length(
git_repository *repo,
const char *path)
{
git_str str = GIT_STR_INIT_CONST(path, SIZE_MAX);
return git_path_validate_str_length(repo, &str);
}
#endif #endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment