Skip to content

Commit 7c69600

Browse files
committed
Merge branch 'jk/fix-refresh-utime' into maint
Fix a small bug in our use of umask() return value. * jk/fix-refresh-utime: check_and_freshen_file: fix reversed success-check
2 parents 3f8b439 + 3096b2e commit 7c69600

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

sha1_file.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,18 +443,26 @@ void prepare_alt_odb(void)
443443
read_info_alternates(get_object_directory(), 0);
444444
}
445445

446+
/* Returns 1 if we have successfully freshened the file, 0 otherwise. */
446447
static int freshen_file(const char *fn)
447448
{
448449
struct utimbuf t;
449450
t.actime = t.modtime = time(NULL);
450451
return !utime(fn, &t);
451452
}
452453

454+
/*
455+
* All of the check_and_freshen functions return 1 if the file exists and was
456+
* freshened (if freshening was requested), 0 otherwise. If they return
457+
* 0, you should not assume that it is safe to skip a write of the object (it
458+
* either does not exist on disk, or has a stale mtime and may be subject to
459+
* pruning).
460+
*/
453461
static int check_and_freshen_file(const char *fn, int freshen)
454462
{
455463
if (access(fn, F_OK))
456464
return 0;
457-
if (freshen && freshen_file(fn))
465+
if (freshen && !freshen_file(fn))
458466
return 0;
459467
return 1;
460468
}

0 commit comments

Comments
 (0)