{"thread":{"id":"11926","subject":"[PATCH v2] Make git prune remove temporary packs that look like write failures","startedAt":"2008-02-06T23:48:33Z","lastAt":"2008-02-07T01:25:20Z","messageCount":2,"participants":["David Steven Tweed","Johannes Schindelin"],"isPatch":true,"patchVersion":2,"patchTotal":null},"messages":[{"id":"67734","messageId":"Pine.GSO.4.63.0802062342020.7187@suma3","threadId":"11926","inReplyTo":null,"subject":"[PATCH v2] Make git prune remove temporary packs that look like write failures","fromName":"David Steven Tweed","fromEmail":"d.s.tweed@reading.ac.uk","sentAt":"2008-02-06T23:48:33Z","receivedAt":"2008-02-06T23:48:33Z","isPatch":true,"sender":{"key":"d.s.tweed@reading.ac.uk","avatar":null},"body":"Write errors when repacking (eg, due to out-of-space conditions)\ncan leave temporary packs (and possibly other files beginning\nwith \"tmp_\") lying around which no existing\ncodepath removes and which aren't obvious to the casual user.\nThese can also be multi-megabyte files wasting noticeable space.\nUnfortunately there's no way to definitely tell in builtin-prune\nthat a tmp_ file is not being used by a concurrent process.\nHowever, it is documented that pruning should only be done\non a quiet repository and --expire is honoured (using code\nfrom Johannes Schindelin). The names of removed files are printed.\n\nSigned-off-by: David Tweed (david.tweed@gmail.com)\n---\n\nThis version incorporates all the agreed with changes from the\nprevious version, and since I was modifying the relevant\ncontext lines it includes Johannes' code honouring --expire\n(but not the test he wrote which is presumably best sent as a separate \npatch from him).\n\nHopefully this one won't get whitespace munged.\n\n builtin-prune.c |   39 +++++++++++++++++++++++++++++++++++++++\n 1 files changed, 39 insertions(+), 0 deletions(-)\n\ndiff --git a/builtin-prune.c b/builtin-prune.c\nindex b5e7684..f25ddb6 100644\n--- a/builtin-prune.c\n+++ b/builtin-prune.c\n@@ -83,6 +83,44 @@ static void prune_object_dir(const char *path)\n \t}\n }\n\n+/*\n+ * Write errors (particularly out of space) can result in\n+ * failed temporary packs (and more rarely indexes and other\n+ * files begining with \"tmp_\") accumulating in the\n+ * object directory.\n+ */\n+static void remove_temporary_files(void)\n+{\n+\tDIR *dir;\n+\tstruct dirent *de;\n+\tchar* dirname=get_object_directory();\n+\n+\tdir = opendir(dirname);\n+\tif (!dir) {\n+\t\tfprintf(stderr, \"Unable to open object directory %s\\n\",\n+\t\t\tdirname);\n+\t\treturn;\n+\t}\n+\twhile ((de = readdir(dir)) != NULL) {\n+\t\tif (!prefixcmp(de->d_name, \"tmp_\")) {\n+\t\t\tchar name[PATH_MAX];\n+\t\t\tint c = snprintf(name, PATH_MAX, \"%s/%s\",\n+\t\t\t\t\t dirname, de->d_name);\n+\t\t\tif (c < 0 || c >= PATH_MAX)\n+\t\t\t\tcontinue;\n+\t\t\tif (expire) {\n+\t\t\t\tstruct stat st;\n+\t\t\t\tif (stat(name, &st) != 0 || st.st_mtime >= expire)\n+\t\t\t\t\tcontinue;\n+\t\t\t}\n+\t\t\tprintf(\"Removing stale temporary file %s\\n\", name);\n+\t\t\tif (!show_only)\n+\t\t\t\tunlink(name);\n+\t\t}\n+\t}\n+\tclosedir(dir);\n+}\n+\n int cmd_prune(int argc, const char **argv, const char *prefix)\n {\n \tint i;\n@@ -115,5 +153,6 @@ int cmd_prune(int argc, const char **argv, const char *prefix)\n\n \tsync();\n \tprune_packed_objects(show_only);\n+\tremove_temporary_files();\n \treturn 0;\n }\n"},{"id":"67740","messageId":"alpine.LSU.1.00.0802070123480.8543@racer.site","threadId":"11926","inReplyTo":"Pine.GSO.4.63.0802062342020.7187@suma3","subject":"Re: [PATCH v2] Make git prune remove temporary packs that look like write failures","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2008-02-07T01:25:20Z","receivedAt":"2008-02-07T01:25:20Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Wed, 6 Feb 2008, David Steven Tweed wrote:\n\n> This version incorporates all the agreed with changes from the previous \n> version, and since I was modifying the relevant context lines it \n> includes Johannes' code honouring --expire (but not the test he wrote \n> which is presumably best sent as a separate patch from him).\n\nNo, I don't want the tests as a separate patch.  They are intrinsic to \nyour patch, since they show that your patch does what it's supposed to do \n(at least in an empirical way).\n\nCiao,\nDscho\n"}]}