diff options
author | Russell Belfer <arrbee@arrbee.com> | 2012-03-12 22:55:40 -0700 |
---|---|---|
committer | Russell Belfer <arrbee@arrbee.com> | 2012-03-12 22:55:40 -0700 |
commit | e1de726c15937a8dbf81d12ef0c872cf6576ebd0 (patch) | |
tree | 84b437dd23e8250b0a4f983875fb3849569ad63a /src/filebuf.c | |
parent | dda708e78f3c3f43d814d46c29ab9f2b9d47ed5c (diff) | |
download | libgit2-e1de726c15937a8dbf81d12ef0c872cf6576ebd0.tar.gz |
Migrate ODB files to new error handling
This migrates odb.c, odb_loose.c, odb_pack.c and pack.c to
the new style of error handling. Also got the unix and win32
versions of map.c. There are some minor changes to other
files but no others were completely converted.
This also contains an update to filebuf so that a zeroed out
filebuf will not think that the fd (== 0) is actually open
(and inadvertently call close() on fd 0 if cleaned up).
Lastly, this was built and tested on win32 and contains a
bunch of fixes for the win32 build which was pretty broken.
Diffstat (limited to 'src/filebuf.c')
-rw-r--r-- | src/filebuf.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/filebuf.c b/src/filebuf.c index 5e206c5d8..09b1e0e59 100644 --- a/src/filebuf.c +++ b/src/filebuf.c @@ -67,6 +67,8 @@ static int lock_file(git_filebuf *file, int flags) if (file->fd < 0) return -1; + file->fd_is_open = true; + if ((flags & GIT_FILEBUF_APPEND) && git_path_exists(file->path_original) == true) { git_file source; char buffer[2048]; @@ -94,10 +96,10 @@ static int lock_file(git_filebuf *file, int flags) void git_filebuf_cleanup(git_filebuf *file) { - if (file->fd >= 0) + if (file->fd_is_open && file->fd >= 0) p_close(file->fd); - if (file->fd >= 0 && file->path_lock && git_path_exists(file->path_lock) == true) + if (file->fd_is_open && file->path_lock && git_path_exists(file->path_lock)) p_unlink(file->path_lock); if (file->digest) @@ -239,6 +241,7 @@ int git_filebuf_open(git_filebuf *file, const char *path, int flags) git_buf_free(&tmp_path); goto cleanup; } + file->fd_is_open = true; /* No original path */ file->path_original = NULL; @@ -308,6 +311,7 @@ int git_filebuf_commit(git_filebuf *file, mode_t mode) p_close(file->fd); file->fd = -1; + file->fd_is_open = false; if (p_chmod(file->path_lock, mode)) { giterr_set(GITERR_OS, "Failed to set attributes for file at '%s'", file->path_lock); |