Skip to content

Commit

Permalink
Merge branch 'jk/fix-refresh-utime' into maint
Browse files Browse the repository at this point in the history
Fix a small bug in our use of umask() return value.

* jk/fix-refresh-utime:
  check_and_freshen_file: fix reversed success-check
  • Loading branch information
gitster committed Jul 27, 2015
2 parents 3f8b439 + 3096b2e commit 7c69600
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion sha1_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -443,18 +443,26 @@ 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;
t.actime = t.modtime = time(NULL);
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;
}
Expand Down

0 comments on commit 7c69600

Please sign in to comment.