Commit 1869b31e by Jakob Pfender

index/fileops: Correctly process symbolic links

gitfo_exists() used to error out if the given file was a symbolic link,
due to access() returning an error code. This is not expected behaviour,
as gitfo_exists() should only check whether the file itself exists, not
its link target if it is a symbolic link.

Fix this by calling gitfo_lstat() instead, which is just a wrapper for
lstat().

Also fix the same error in index_init_entry().
parent 4d7905c5
...@@ -172,7 +172,9 @@ int gitfo_isfile(const char *path) ...@@ -172,7 +172,9 @@ int gitfo_isfile(const char *path)
int gitfo_exists(const char *path) int gitfo_exists(const char *path)
{ {
assert(path); assert(path);
return access(path, F_OK);
struct stat st;
return gitfo_lstat(path, &st);
} }
git_off_t gitfo_size(git_file fd) git_off_t gitfo_size(git_file fd)
......
...@@ -94,6 +94,7 @@ extern int gitfo_mv_force(const char *from, const char *to); ...@@ -94,6 +94,7 @@ extern int gitfo_mv_force(const char *from, const char *to);
#define gitfo_stat(p,b) stat(p, b) #define gitfo_stat(p,b) stat(p, b)
#define gitfo_fstat(f,b) fstat(f, b) #define gitfo_fstat(f,b) fstat(f, b)
#define gitfo_lstat(p,b) lstat(p,b)
#define gitfo_unlink(p) unlink(p) #define gitfo_unlink(p) unlink(p)
#define gitfo_rmdir(p) rmdir(p) #define gitfo_rmdir(p) rmdir(p)
......
...@@ -405,7 +405,7 @@ static int index_init_entry(git_index_entry *entry, git_index *index, const char ...@@ -405,7 +405,7 @@ static int index_init_entry(git_index_entry *entry, git_index *index, const char
if (gitfo_exists(full_path) < 0) if (gitfo_exists(full_path) < 0)
return git__throw(GIT_ENOTFOUND, "Failed to initialize entry. %s does not exist", full_path); return git__throw(GIT_ENOTFOUND, "Failed to initialize entry. %s does not exist", full_path);
if (gitfo_stat(full_path, &st) < 0) if (gitfo_lstat(full_path, &st) < 0)
return git__throw(GIT_EOSERR, "Failed to initialize entry. %s appears to be corrupted", full_path); return git__throw(GIT_EOSERR, "Failed to initialize entry. %s appears to be corrupted", full_path);
if (stage < 0 || stage > 3) if (stage < 0 || stage > 3)
......
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