Skip to content

Commit fb8b193

Browse files
jherlandgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5a688fe commit fb8b193

File tree

5 files changed

+4
-11
lines changed

5 files changed

+4
-11
lines changed

fast-import.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -902,9 +902,6 @@ static char *keep_pack(char *curr_index_name)
902902
static const char *keep_msg = "fast-import";
903903
int keep_fd;
904904

905-
chmod(pack_data->pack_name, 0444);
906-
chmod(curr_index_name, 0444);
907-
908905
keep_fd = odb_pack_keep(name, sizeof(name), pack_data->sha1);
909906
if (keep_fd < 0)
910907
die("cannot create keep file");

http-push.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,6 @@ static void finish_request(struct transfer_request *request)
748748
aborted = 1;
749749
}
750750
} else if (request->state == RUN_FETCH_LOOSE) {
751-
fchmod(request->local_fileno, 0444);
752751
close(request->local_fileno); request->local_fileno = -1;
753752

754753
if (request->curl_result != CURLE_OK &&

http-walker.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,6 @@ static void finish_object_request(struct object_request *obj_req)
231231
{
232232
struct stat st;
233233

234-
fchmod(obj_req->local, 0444);
235234
close(obj_req->local); obj_req->local = -1;
236235

237236
if (obj_req->http_code == 416) {

index-pack.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -823,8 +823,7 @@ static void final(const char *final_pack_name, const char *curr_pack_name,
823823
}
824824
if (move_temp_to_file(curr_pack_name, final_pack_name))
825825
die("cannot store pack file");
826-
}
827-
if (from_stdin)
826+
} else if (from_stdin)
828827
chmod(final_pack_name, 0444);
829828

830829
if (final_index_name != curr_index_name) {
@@ -835,8 +834,8 @@ static void final(const char *final_pack_name, const char *curr_pack_name,
835834
}
836835
if (move_temp_to_file(curr_index_name, final_index_name))
837836
die("cannot store index file");
838-
}
839-
chmod(final_index_name, 0444);
837+
} else
838+
chmod(final_index_name, 0444);
840839

841840
if (!from_stdin) {
842841
printf("%s\n", sha1_to_hex(sha1));

sha1_file.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2279,7 +2279,7 @@ int move_temp_to_file(const char *tmpfile, const char *filename)
22792279
/* FIXME!!! Collision check here ? */
22802280
}
22812281

2282-
if (adjust_shared_perm(filename))
2282+
if (chmod(filename, 0444) || adjust_shared_perm(filename))
22832283
return error("unable to set permission to '%s'", filename);
22842284
return 0;
22852285
}
@@ -2305,7 +2305,6 @@ static void close_sha1_file(int fd)
23052305
{
23062306
if (fsync_object_files)
23072307
fsync_or_die(fd, "sha1 file");
2308-
fchmod(fd, 0444);
23092308
if (close(fd) != 0)
23102309
die("error when closing sha1 file (%s)", strerror(errno));
23112310
}

0 commit comments

Comments
 (0)