On 2/26/2018 9:32 PM, Derrick Stolee wrote:
This patch is new to the series due to the interactions with the lockfile API
and the hashfile API. I need to ensure the hashfile writes the hash value at
the end of the file, but keep the file descriptor open so the lock is valid.
I welcome any susggestions to this patch or to the way I use it in the commit
that follows.
-- >8 --
I haven't gotten any feedback on this step of the patch. Could someone
take a look and let me know what you think?
Thanks,
-Stolee
If we want to use a hashfile on the temporary file for a lockfile, then
we need hashclose() to fully write the trailing hash but also keep the
file descriptor open.
Signed-off-by: Derrick Stolee <dstolee@xxxxxxxxxxxxx>
---
csum-file.c | 10 +++++++---
csum-file.h | 1 +
2 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/csum-file.c b/csum-file.c
index 5eda7fb..302e6ae 100644
--- a/csum-file.c
+++ b/csum-file.c
@@ -66,9 +66,13 @@ int hashclose(struct hashfile *f, unsigned char *result, unsigned int flags)
flush(f, f->buffer, the_hash_algo->rawsz);
if (flags & CSUM_FSYNC)
fsync_or_die(f->fd, f->name);
- if (close(f->fd))
- die_errno("%s: sha1 file error on close", f->name);
- fd = 0;
+ if (flags & CSUM_KEEP_OPEN)
+ fd = f->fd;
+ else {
+ if (close(f->fd))
+ die_errno("%s: sha1 file error on close", f->name);
+ fd = 0;
+ }
} else
fd = f->fd;
if (0 <= f->check_fd) {
diff --git a/csum-file.h b/csum-file.h
index 992e5c0..b7c0e48 100644
--- a/csum-file.h
+++ b/csum-file.h
@@ -29,6 +29,7 @@ extern int hashfile_truncate(struct hashfile *, struct hashfile_checkpoint *);
/* hashclose flags */
#define CSUM_CLOSE 1
#define CSUM_FSYNC 2
+#define CSUM_KEEP_OPEN 4
extern struct hashfile *hashfd(int fd, const char *name);
extern struct hashfile *hashfd_check(const char *name);