register_tempfile(): new function to handle an existing temporary file
Allow an existing file to be registered with the tempfile-handling infrastructure; in particular, arrange for it to be deleted on program exit. This can be used if the temporary file has to be created in a more complicated way than just open(). For example: * If the file itself needs to be created via the lockfile API * If it is not a regular file (e.g., a socket) Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Michael Haggerty committed
Aug 10, 2015 at 11:47 UTC
99397152a345011c99497b93f8518c7981e811a5
2 files changed
+16
tempfile.c
+8
@@ -137,6 +137,14 @@ int create_tempfile(struct tempfile *tempfile, const char *path)
137
return tempfile->fd;
138
}
139
140
+void register_tempfile(struct tempfile *tempfile, const char *path)
141
+{
142
+ prepare_tempfile_object(tempfile);
143
+ strbuf_add_absolute_path(&tempfile->filename, path);
144
+ tempfile->owner = getpid();
145
+ tempfile->active = 1;
146
+}
147
+
148
int mks_tempfile_sm(struct tempfile *tempfile,
149
const char *template, int suffixlen, int mode)
150
{
tempfile.h
+8
@@ -92,6 +92,14 @@ struct tempfile {
92
*/
93
extern int create_tempfile(struct tempfile *tempfile, const char *path);
94
95
+/*
96
+ * Register an existing file as a tempfile, meaning that it will be
97
+ * deleted when the program exits. The tempfile is considered closed,
98
+ * but it can be worked with like any other closed tempfile (for
99
+ * example, it can be opened using reopen_tempfile()).
100
+ */
101
+extern void register_tempfile(struct tempfile *tempfile, const char *path);
102
+
103
104
/*
105
* mks_tempfile functions