{"thread":{"id":"7381","subject":"[PATCH] make it more obvious that temporary files are temporary files","startedAt":"2007-03-24T15:58:22Z","lastAt":"2007-03-24T15:58:22Z","messageCount":1,"participants":["Nicolas Pitre"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"37886","messageId":"alpine.LFD.0.83.0703241151010.18328@xanadu.home","threadId":"7381","inReplyTo":null,"subject":"[PATCH] make it more obvious that temporary files are temporary files","fromName":"Nicolas Pitre","fromEmail":"nico@cam.org","sentAt":"2007-03-24T15:58:22Z","receivedAt":"2007-03-24T15:58:22Z","isPatch":true,"sender":{"key":"nico@fluxnic.net","avatar":"https://avatars.githubusercontent.com/u/702790?v=4"},"body":"When some operations are interrupted (or \"die()'d\" or crashed) then the \npartial object/pack/index file may remain around.  Make it more obvious \nin their name that those files are temporary stuff and can be cleaned up \nif no operation is in progress.\n\nSigned-off-by: Nicolas Pitre <nico@cam.org>\n---\n\ndiff --git a/fast-import.c b/fast-import.c\nindex 55ffae4..bea1215 100644\n--- a/fast-import.c\n+++ b/fast-import.c\n@@ -630,7 +630,7 @@ static void start_packfile(void)\n \tint pack_fd;\n \n \tsnprintf(tmpfile, sizeof(tmpfile),\n-\t\t\"%s/pack_XXXXXX\", get_object_directory());\n+\t\t\"%s/tmp_pack_XXXXXX\", get_object_directory());\n \tpack_fd = mkstemp(tmpfile);\n \tif (pack_fd < 0)\n \t\tdie(\"Can't create %s: %s\", tmpfile, strerror(errno));\n@@ -730,7 +730,7 @@ static char *create_index(void)\n \t}\n \n \tsnprintf(tmpfile, sizeof(tmpfile),\n-\t\t\"%s/index_XXXXXX\", get_object_directory());\n+\t\t\"%s/tmp_idx_XXXXXX\", get_object_directory());\n \tidx_fd = mkstemp(tmpfile);\n \tif (idx_fd < 0)\n \t\tdie(\"Can't create %s: %s\", tmpfile, strerror(errno));\ndiff --git a/index-pack.c b/index-pack.c\nindex 61eb20e..6284fe3 100644\n--- a/index-pack.c\n+++ b/index-pack.c\n@@ -139,7 +139,7 @@ static const char *open_pack_file(const char *pack_name)\n \t\tif (!pack_name) {\n \t\t\tstatic char tmpfile[PATH_MAX];\n \t\t\tsnprintf(tmpfile, sizeof(tmpfile),\n-\t\t\t\t \"%s/pack_XXXXXX\", get_object_directory());\n+\t\t\t\t \"%s/tmp_pack_XXXXXX\", get_object_directory());\n \t\t\toutput_fd = mkstemp(tmpfile);\n \t\t\tpack_name = xstrdup(tmpfile);\n \t\t} else\n@@ -690,7 +690,7 @@ static const char *write_index_file(const char *index_name, unsigned char *sha1)\n \tif (!index_name) {\n \t\tstatic char tmpfile[PATH_MAX];\n \t\tsnprintf(tmpfile, sizeof(tmpfile),\n-\t\t\t \"%s/index_XXXXXX\", get_object_directory());\n+\t\t\t \"%s/tmp_idx_XXXXXX\", get_object_directory());\n \t\tfd = mkstemp(tmpfile);\n \t\tindex_name = xstrdup(tmpfile);\n \t} else {\ndiff --git a/sha1_file.c b/sha1_file.c\nindex 940bab5..0897b94 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -1979,7 +1979,7 @@ int write_sha1_file(void *buf, unsigned long len, const char *type, unsigned cha\n \t\treturn error(\"sha1 file %s: %s\\n\", filename, strerror(errno));\n \t}\n \n-\tsnprintf(tmpfile, sizeof(tmpfile), \"%s/obj_XXXXXX\", get_object_directory());\n+\tsnprintf(tmpfile, sizeof(tmpfile), \"%s/tmp_obj_XXXXXX\", get_object_directory());\n \n \tfd = mkstemp(tmpfile);\n \tif (fd < 0) {\n@@ -2105,7 +2105,7 @@ int write_sha1_from_fd(const unsigned char *sha1, int fd, char *buffer,\n \tint ret;\n \tSHA_CTX c;\n \n-\tsnprintf(tmpfile, sizeof(tmpfile), \"%s/obj_XXXXXX\", get_object_directory());\n+\tsnprintf(tmpfile, sizeof(tmpfile), \"%s/tmp_obj_XXXXXX\", get_object_directory());\n \n \tlocal = mkstemp(tmpfile);\n \tif (local < 0) {\n"}]}