diff options
| author | Patrick Steinhardt <ps@pks.im> | 2019-06-29 09:58:34 +0200 |
|---|---|---|
| committer | Patrick Steinhardt <ps@pks.im> | 2019-07-20 19:11:20 +0200 |
| commit | ded77bb1f18c6cb7a0371b3f66c92387413a161d (patch) | |
| tree | 44b95bb7a1998304a57b86f9892e92e2da0a2cb6 /src/path.c | |
| parent | e54343a4024e75dfaa940e652c2c9799d33634b2 (diff) | |
| download | libgit2-ded77bb1f18c6cb7a0371b3f66c92387413a161d.tar.gz | |
path: extract function to check whether a path supports symlinks
When initializing a repository, we need to check whether its working
directory supports symlinks to correctly set the initial value of the
"core.symlinks" config variable. The code to check the filesystem is
reusable in other parts of our codebase, like for example in our tests
to determine whether certain tests can be expected to succeed or not.
Extract the code into a new function `git_path_supports_symlinks` to
avoid duplicate implementations. Remove a duplicate implementation in
the repo test helper code.
Diffstat (limited to 'src/path.c')
| -rw-r--r-- | src/path.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/path.c b/src/path.c index df6b6233b..41232c2f6 100644 --- a/src/path.c +++ b/src/path.c @@ -1924,3 +1924,25 @@ extern int git_path_is_gitfile(const char *path, size_t pathlen, git_path_gitfil return -1; } } + +bool git_path_supports_symlinks(const char *dir) +{ + git_buf path = GIT_BUF_INIT; + bool supported = false; + struct stat st; + int fd; + + if ((fd = git_futils_mktmp(&path, dir, 0666)) < 0 || + p_close(fd) < 0 || + p_unlink(path.ptr) < 0 || + p_symlink("testing", path.ptr) < 0 || + p_lstat(path.ptr, &st) < 0) + goto done; + + supported = (S_ISLNK(st.st_mode) != 0); +done: + if (path.size) + (void)p_unlink(path.ptr); + git_buf_dispose(&path); + return supported; +} |
