summaryrefslogtreecommitdiff
path: root/src/path.c
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2013-10-08 12:45:43 -0700
committerRussell Belfer <rb@github.com>2013-10-08 12:45:43 -0700
commit14997dc5f69e7ceebe502b32087d809a8482bf78 (patch)
treeff245ed60887dc4eddd3b3ea65e7dd215deeeb62 /src/path.c
parent5173ea921d4ccbbe7d61ddce9a0920c2e1c82035 (diff)
downloadlibgit2-14997dc5f69e7ceebe502b32087d809a8482bf78.tar.gz
More filemode cleanups for FAT on MacOS
This cleans up some additional issues. The main change is that on a filesystem that doesn't support mode bits, libgit2 will now create new blobs with GIT_FILEMODE_BLOB always instead of being at the mercy to the filesystem driver to report executable or not. This means that if "core.filemode" lies and claims that filemode is not supported, then we will ignore the executable bit from the filesystem. Previously we would have allowed it. This adds an option to the new git_repository_reset_filesystem to recurse through submodules if desired. There may be other types of APIs that would like a "recurse submodules" option, but this one is particularly useful. This also has a number of cleanups, etc., for related things including trying to give better error messages when problems come up from the filesystem. For example, the FAT filesystem driver on MacOS appears to return errno EINVAL if you attempt to write a filename with invalid UTF-8 in it. We try to capture that with a better error message now.
Diffstat (limited to 'src/path.c')
-rw-r--r--src/path.c33
1 files changed, 26 insertions, 7 deletions
diff --git a/src/path.c b/src/path.c
index 27abd062b..d45751cd1 100644
--- a/src/path.c
+++ b/src/path.c
@@ -538,16 +538,35 @@ bool git_path_is_empty_dir(const char *path)
#endif
-int git_path_lstat(const char *path, struct stat *st)
+int git_path_set_error(int errno_value, const char *path, const char *action)
{
- int err = 0;
-
- if (p_lstat(path, st) < 0) {
- err = (errno == ENOENT) ? GIT_ENOTFOUND : -1;
- giterr_set(GITERR_OS, "Failed to stat file '%s'", path);
+ switch (errno_value) {
+ case ENOENT:
+ case ENOTDIR:
+ giterr_set(GITERR_OS, "Could not find '%s' to %s", path, action);
+ return GIT_ENOTFOUND;
+
+ case EINVAL:
+ case ENAMETOOLONG:
+ giterr_set(GITERR_OS, "Invalid path for filesystem '%s'", path);
+ return GIT_EINVALIDSPEC;
+
+ case EEXIST:
+ giterr_set(GITERR_OS, "Failed %s - '%s' already exists", action, path);
+ return GIT_EEXISTS;
+
+ default:
+ giterr_set(GITERR_OS, "Could not %s '%s'", action, path);
+ return -1;
}
+}
+
+int git_path_lstat(const char *path, struct stat *st)
+{
+ if (p_lstat(path, st) == 0)
+ return 0;
- return err;
+ return git_path_set_error(errno, path, "stat");
}
static bool _check_dir_contents(