diff --git a/sha1_file.c b/sha1_file.c index c63264198ea3b52c78387e2f949b3cac7a7a256f..5475d781d4961e24e0b3165c45c337cbaf2a3557 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -442,6 +442,7 @@ void prepare_alt_odb(void) read_info_alternates(get_object_directory(), 0); } +/* Returns 1 if we have successfully freshened the file, 0 otherwise. */ static int freshen_file(const char *fn) { struct utimbuf t; @@ -449,11 +450,18 @@ static int freshen_file(const char *fn) return !utime(fn, &t); } +/* + * All of the check_and_freshen functions return 1 if the file exists and was + * freshened (if freshening was requested), 0 otherwise. If they return + * 0, you should not assume that it is safe to skip a write of the object (it + * either does not exist on disk, or has a stale mtime and may be subject to + * pruning). + */ static int check_and_freshen_file(const char *fn, int freshen) { if (access(fn, F_OK)) return 0; - if (freshen && freshen_file(fn)) + if (freshen && !freshen_file(fn)) return 0; return 1; }