X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=sha1_file.c;h=8fe135dc61908103cf2d7de700794843f83db057;hb=70af4e9bef988a98061237c78cbd0a71d8de48bb;hp=37e833b77d1ee556d18256154073a706ab11b3a4;hpb=81aa96497686bd31c5a9a3cdf110c2e10c799c03;p=git.git diff --git a/sha1_file.c b/sha1_file.c index 37e833b77..8fe135dc6 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -2216,11 +2216,15 @@ static void write_sha1_file_prepare(const void *buf, unsigned long len, } /* - * Move the just written object into its final resting place + * Move the just written object into its final resting place. + * NEEDSWORK: this should be renamed to finalize_temp_file() as + * "moving" is only a part of what it does, when no patch between + * master to pu changes the call sites of this function. */ int move_temp_to_file(const char *tmpfile, const char *filename) { int ret = 0; + if (link(tmpfile, filename)) ret = errno; @@ -2232,12 +2236,12 @@ int move_temp_to_file(const char *tmpfile, const char *filename) * * The same holds for FAT formatted media. * - * When this succeeds, we just return 0. We have nothing + * When this succeeds, we just return. We have nothing * left to unlink. */ if (ret && ret != EEXIST) { if (!rename(tmpfile, filename)) - return 0; + goto out; ret = errno; } unlink(tmpfile); @@ -2248,6 +2252,9 @@ int move_temp_to_file(const char *tmpfile, const char *filename) /* FIXME!!! Collision check here ? */ } +out: + if (set_shared_perm(filename, (S_IFREG|0444))) + return error("unable to set permission to '%s'", filename); return 0; } @@ -2272,7 +2279,6 @@ static void close_sha1_file(int fd) { if (fsync_object_files) fsync_or_die(fd, "sha1 file"); - fchmod(fd, 0444); if (close(fd) != 0) die("error when closing sha1 file (%s)", strerror(errno)); }