Move chmod(foo, 0444) into move_temp_to_file()
When writing out a loose object or a pack (index), move_temp_to_file() is called to finalize the resulting file. These files (loose files and packs) should all have permission mode 0444 (modulo adjust_shared_perm()). Therefore, instead of doing chmod(foo, 0444) explicitly from each callsite (or even forgetting to chmod() at all), do the chmod() call from within move_temp_to_file(). Signed-off-by: Johan Herland <johan@herland.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Johan Herland committed
Mar 26, 2009 at 16:16 UTC
fb8b193670b0c11d118185332efc899d6d01d5f4
5 files changed
+4
-11
fast-import.c
-3
@@ -902,9 +902,6 @@ static char *keep_pack(char *curr_index_name)
902
static const char *keep_msg = "fast-import";
903
int keep_fd;
904
905
- chmod(pack_data->pack_name, 0444);
906
- chmod(curr_index_name, 0444);
907
-
905
keep_fd = odb_pack_keep(name, sizeof(name), pack_data->sha1);
906
if (keep_fd < 0)
907
die("cannot create keep file");
http-push.c
-1
@@ -748,7 +748,6 @@ static void finish_request(struct transfer_request *request)
748
aborted = 1;
749
}
750
} else if (request->state == RUN_FETCH_LOOSE) {
751
- fchmod(request->local_fileno, 0444);
751
close(request->local_fileno); request->local_fileno = -1;
752
753
if (request->curl_result != CURLE_OK &&
http-walker.c
-1
@@ -231,7 +231,6 @@ static void finish_object_request(struct object_request *obj_req)
231
{
232
struct stat st;
233
234
- fchmod(obj_req->local, 0444);
234
close(obj_req->local); obj_req->local = -1;
235
236
if (obj_req->http_code == 416) {
index-pack.c
+3
-4
@@ -823,8 +823,7 @@ static void final(const char *final_pack_name, const char *curr_pack_name,
823
}
824
if (move_temp_to_file(curr_pack_name, final_pack_name))
825
die("cannot store pack file");
826
- }
827
- if (from_stdin)
826
+ } else if (from_stdin)
827
chmod(final_pack_name, 0444);
828
829
if (final_index_name != curr_index_name) {
@@ -835,8 +834,8 @@ static void final(const char *final_pack_name, const char *curr_pack_name,
834
}
835
if (move_temp_to_file(curr_index_name, final_index_name))
836
die("cannot store index file");
838
- }
839
- chmod(final_index_name, 0444);
837
+ } else
838
+ chmod(final_index_name, 0444);
839
840
if (!from_stdin) {
841
printf("%s\n", sha1_to_hex(sha1));
sha1_file.c
+1
-2
@@ -2279,7 +2279,7 @@ int move_temp_to_file(const char *tmpfile, const char *filename)
2279
/* FIXME!!! Collision check here ? */
2280
}
2281
2282
- if (adjust_shared_perm(filename))
2282
+ if (chmod(filename, 0444) || adjust_shared_perm(filename))
2283
return error("unable to set permission to '%s'", filename);
2284
return 0;
2285
}
@@ -2305,7 +2305,6 @@ static void close_sha1_file(int fd)
2305
{
2306
if (fsync_object_files)
2307
fsync_or_die(fd, "sha1 file");
2308
- fchmod(fd, 0444);
2308
if (close(fd) != 0)
2309
die("error when closing sha1 file (%s)", strerror(errno));
2310
}