Skip to content

Commit 89c571d

Browse files
mhaggergitster
authored andcommitted
read_packed_refs(): report unexpected fopen() failures
The old code ignored any errors encountered when trying to fopen the "packed-refs" file, treating all such failures as if the file didn't exist. But it could be that there is some other error opening the file (e.g., permissions problems), and we don't want to silently ignore such problems. So report any failures that are not due to ENOENT. Signed-off-by: Michael Haggerty <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 099a912 commit 89c571d

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

refs/files-backend.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,18 @@ static struct packed_ref_cache *read_packed_refs(const char *packed_refs_file)
251251
packed_refs->cache->root->flag &= ~REF_INCOMPLETE;
252252

253253
f = fopen(packed_refs_file, "r");
254-
if (!f)
255-
return packed_refs;
254+
if (!f) {
255+
if (errno == ENOENT) {
256+
/*
257+
* This is OK; it just means that no
258+
* "packed-refs" file has been written yet,
259+
* which is equivalent to it being empty.
260+
*/
261+
return packed_refs;
262+
} else {
263+
die_errno("couldn't read %s", packed_refs_file);
264+
}
265+
}
256266

257267
stat_validity_update(&packed_refs->validity, fileno(f));
258268

0 commit comments

Comments
 (0)