diff options
author | Derrick Stolee <dstolee@microsoft.com> | 2018-04-02 22:34:15 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2018-04-02 23:27:30 +0200 |
commit | cfe83216e404223ce8c5f6ef79c4ba9a27ff872e (patch) | |
tree | 6f64a9ccff4777e87bd43fdf8e051a215048ae63 /csum-file.c | |
parent | csum-file: rename hashclose() to finalize_hashfile() (diff) | |
download | git-cfe83216e404223ce8c5f6ef79c4ba9a27ff872e.tar.xz git-cfe83216e404223ce8c5f6ef79c4ba9a27ff872e.zip |
csum-file: refactor finalize_hashfile() method
If we want to use a hashfile on the temporary file for a lockfile, then
we need finalize_hashfile() to fully write the trailing hash but also keep
the file descriptor open.
Do this by adding a new CSUM_HASH_IN_STREAM flag along with a functional
change that checks this flag before writing the checksum to the stream.
This differs from previous behavior since it would be written if either
CSUM_CLOSE or CSUM_FSYNC is provided.
Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'csum-file.c')
-rw-r--r-- | csum-file.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/csum-file.c b/csum-file.c index e6c95a6915..53ce37f7ca 100644 --- a/csum-file.c +++ b/csum-file.c @@ -61,11 +61,11 @@ int finalize_hashfile(struct hashfile *f, unsigned char *result, unsigned int fl the_hash_algo->final_fn(f->buffer, &f->ctx); if (result) hashcpy(result, f->buffer); - if (flags & (CSUM_CLOSE | CSUM_FSYNC)) { - /* write checksum and close fd */ + if (flags & CSUM_HASH_IN_STREAM) flush(f, f->buffer, the_hash_algo->rawsz); - if (flags & CSUM_FSYNC) - fsync_or_die(f->fd, f->name); + if (flags & CSUM_FSYNC) + fsync_or_die(f->fd, f->name); + if (flags & CSUM_CLOSE) { if (close(f->fd)) die_errno("%s: sha1 file error on close", f->name); fd = 0; |