@ -2216,11 +2216,15 @@ static void write_sha1_file_prepare(const void *buf, unsigned long len,
@@ -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)
@@ -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)
@@ -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)
@@ -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));
}