X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;ds=sidebyside;f=csum-file.c;h=ace64f165e4a01fb99892e9b89e7df791a7f4ca1;hb=a7b3269c4b9acde052d75b6dc54c8f869b77eb44;hp=9728a9954129246b96713d2f3b8dbd52541c416b;hpb=c78a24986d4d3faff810e87dbcd0ac99f0eabbce;p=git.git diff --git a/csum-file.c b/csum-file.c index 9728a9954..ace64f165 100644 --- a/csum-file.c +++ b/csum-file.c @@ -32,21 +32,24 @@ static void sha1flush(struct sha1file *f, unsigned int count) } } -int sha1close(struct sha1file *f, unsigned char *result, int final) +int sha1close(struct sha1file *f, unsigned char *result, unsigned int flags) { int fd; unsigned offset = f->offset; + if (offset) { SHA1_Update(&f->ctx, f->buffer, offset); sha1flush(f, offset); f->offset = 0; } - if (final) { + if (flags & (CSUM_CLOSE | CSUM_FSYNC)) { /* write checksum and close fd */ SHA1_Final(f->buffer, &f->ctx); if (result) hashcpy(result, f->buffer); sha1flush(f, 20); + if (flags & CSUM_FSYNC) + fsync_or_die(f->fd, f->name); if (close(f->fd)) die("%s: sha1 file error on close (%s)", f->name, strerror(errno));