git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] prune: keep files created after process start
@ 2016-06-19  3:13 Eric Wong
  2016-06-19  3:58 ` Junio C Hamano
  2016-06-19  7:11 ` Andreas Schwab
  0 siblings, 2 replies; 6+ messages in thread
From: Eric Wong @ 2016-06-19  3:13 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

Avoid pruning files which were written after the prune process
starts, as it possible to concurrently create new objects while
"git prune" is running.

Tested on git.git by starting "git prune" in one terminal,
creating a random loose object via "git hash-object --stdin -w"
in a different terminal, and ensuring the loose object remains
after "git prune" completes.

Signed-off-by: Eric Wong <e@80x24.org>
---
 I'm somewhat surprised this check didn't already exist;
 but maybe nobody else runs prune manually, anymore.

 builtin/prune.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/builtin/prune.c b/builtin/prune.c
index 8f4f052..d4cd054 100644
--- a/builtin/prune.c
+++ b/builtin/prune.c
@@ -14,6 +14,7 @@ static const char * const prune_usage[] = {
 static int show_only;
 static int verbose;
 static unsigned long expire;
+static time_t start;
 static int show_progress = -1;
 
 static int prune_tmp_file(const char *fullpath)
@@ -21,7 +22,7 @@ static int prune_tmp_file(const char *fullpath)
 	struct stat st;
 	if (lstat(fullpath, &st))
 		return error("Could not stat '%s'", fullpath);
-	if (st.st_mtime > expire)
+	if (st.st_mtime > expire || st.st_ctime >= start)
 		return 0;
 	if (show_only || verbose)
 		printf("Removing stale temporary file %s\n", fullpath);
@@ -47,7 +48,7 @@ static int prune_object(const unsigned char *sha1, const char *fullpath,
 		error("Could not stat '%s'", fullpath);
 		return 0;
 	}
-	if (st.st_mtime > expire)
+	if (st.st_mtime > expire || st.st_ctime >= start)
 		return 0;
 	if (show_only || verbose) {
 		enum object_type type = sha1_object_info(sha1, NULL);
@@ -111,6 +112,7 @@ int cmd_prune(int argc, const char **argv, const char *prefix)
 	};
 	char *s;
 
+	start = time(NULL);
 	expire = ULONG_MAX;
 	save_commit_buffer = 0;
 	check_replace_refs = 0;

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2016-06-19  9:34 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-06-19  3:13 [PATCH] prune: keep files created after process start Eric Wong
2016-06-19  3:58 ` Junio C Hamano
2016-06-19  4:32   ` Eric Wong
2016-06-19  9:34   ` Jeff King
2016-06-19  7:11 ` Andreas Schwab
2016-06-19  8:48   ` Eric Wong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).