Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVicent Martí <vicent@github.com>2013-08-14 17:40:38 +0400
committerVicent Martí <vicent@github.com>2013-08-14 17:40:38 +0400
commit89f6d84ccfb0c6c840f2adbe968498b9736d31b0 (patch)
tree93526f3147232c30fa25069fe7fe4c8b029c407a /src/fileops.c
parentd5904eb865374ee10aa928ea6d4bbde099cc2ff9 (diff)
parent9ccdb21155b3c9650acf58c55b2596c3503ea14d (diff)
Merge pull request #1781 from brodie/brodie/stat-before-open
fileops: stat() before open()ing in git_futils_readbuffer_updated()
Diffstat (limited to 'src/fileops.c')
-rw-r--r--src/fileops.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/src/fileops.c b/src/fileops.c
index aea8075d5..3a5a53074 100644
--- a/src/fileops.c
+++ b/src/fileops.c
@@ -147,6 +147,7 @@ int git_futils_readbuffer_fd(git_buf *buf, git_file fd, size_t len)
int git_futils_readbuffer_updated(
git_buf *buf, const char *path, time_t *mtime, size_t *size, int *updated)
{
+ int error = 0;
git_file fd;
struct stat st;
bool changed = false;
@@ -156,11 +157,15 @@ int git_futils_readbuffer_updated(
if (updated != NULL)
*updated = 0;
- if ((fd = git_futils_open_ro(path)) < 0)
- return fd;
+ if (p_stat(path, &st) < 0) {
+ error = errno;
+ giterr_set(GITERR_OS, "Failed to stat '%s'", path);
+ if (error == ENOENT || error == ENOTDIR)
+ return GIT_ENOTFOUND;
+ return -1;
+ }
- if (p_fstat(fd, &st) < 0 || S_ISDIR(st.st_mode) || !git__is_sizet(st.st_size+1)) {
- p_close(fd);
+ if (S_ISDIR(st.st_mode) || !git__is_sizet(st.st_size+1)) {
giterr_set(GITERR_OS, "Invalid regular file stat for '%s'", path);
return -1;
}
@@ -177,7 +182,6 @@ int git_futils_readbuffer_updated(
changed = true;
if (!changed) {
- p_close(fd);
return 0;
}
@@ -186,6 +190,9 @@ int git_futils_readbuffer_updated(
if (size != NULL)
*size = (size_t)st.st_size;
+ if ((fd = git_futils_open_ro(path)) < 0)
+ return fd;
+
if (git_futils_readbuffer_fd(buf, fd, (size_t)st.st_size) < 0) {
p_close(fd);
return -1;