object-file: pass filename to fsync_or_die
If we die while trying to fsync a loose object file, pass the actual filename we're trying to sync. This is likely to be more helpful for a user trying to diagnose the cause of the failure than the former 'loose object file' string. It also sidesteps any concerns about translating the die message differently for loose objects versus something else that has a real path. Reported-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Neeraj Singh <neerajsi@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Neeraj Singh committed
Mar 30, 2022 at 18:14 UTC
c4e707f858813c097bd8b488baae07096aa280ad
1 file changed
+4
-4
object-file.c
+4
-4
@@ -1888,16 +1888,16 @@ void hash_object_file(const struct git_hash_algo *algo, const void *buf,
1888
}
1889
1890
/* Finalize a file on disk, and close it. */
1891
-static void close_loose_object(int fd)
1891
+static void close_loose_object(int fd, const char *filename)
1892
{
1893
if (the_repository->objects->odb->will_destroy)
1894
goto out;
1895
1896
if (fsync_object_files > 0)
1897
- fsync_or_die(fd, "loose object file");
1897
+ fsync_or_die(fd, filename);
1898
else
1899
fsync_component_or_die(FSYNC_COMPONENT_LOOSE_OBJECT, fd,
1900
- "loose object file");
1900
+ filename);
1901
1902
out:
1903
if (close(fd) != 0)
@@ -2011,7 +2011,7 @@ static int write_loose_object(const struct object_id *oid, char *hdr,
2011
die(_("confused by unstable object source data for %s"),
2012
oid_to_hex(oid));
2013
2014
- close_loose_object(fd);
2014
+ close_loose_object(fd, tmp_file.buf);
2015
2016
if (mtime) {
2017
struct utimbuf utb;