summaryrefslogtreecommitdiff
path: root/src/repository.c
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2019-06-29 09:58:34 +0200
committerPatrick Steinhardt <ps@pks.im>2019-07-20 19:11:20 +0200
commitded77bb1f18c6cb7a0371b3f66c92387413a161d (patch)
tree44b95bb7a1998304a57b86f9892e92e2da0a2cb6 /src/repository.c
parente54343a4024e75dfaa940e652c2c9799d33634b2 (diff)
downloadlibgit2-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/repository.c')
-rw-r--r--src/repository.c14
1 files changed, 1 insertions, 13 deletions
diff --git a/src/repository.c b/src/repository.c
index 6a49899ad..f9c4ef42a 100644
--- a/src/repository.c
+++ b/src/repository.c
@@ -1419,9 +1419,6 @@ static bool are_symlinks_supported(const char *wd_path)
git_buf xdg_buf = GIT_BUF_INIT;
git_buf system_buf = GIT_BUF_INIT;
git_buf programdata_buf = GIT_BUF_INIT;
- git_buf path = GIT_BUF_INIT;
- int fd;
- struct stat st;
int symlinks = 0;
/*
@@ -1448,23 +1445,14 @@ static bool are_symlinks_supported(const char *wd_path)
goto done;
#endif
- if ((fd = git_futils_mktmp(&path, wd_path, 0666)) < 0 ||
- p_close(fd) < 0 ||
- p_unlink(path.ptr) < 0 ||
- p_symlink("testing", path.ptr) < 0 ||
- p_lstat(path.ptr, &st) < 0)
+ if (!(symlinks = git_path_supports_symlinks(wd_path)))
goto done;
- symlinks = (S_ISLNK(st.st_mode) != 0);
-
- (void)p_unlink(path.ptr);
-
done:
git_buf_dispose(&global_buf);
git_buf_dispose(&xdg_buf);
git_buf_dispose(&system_buf);
git_buf_dispose(&programdata_buf);
- git_buf_dispose(&path);
git_config_free(config);
return symlinks != 0;
}