Re: [PATCH 07/14] register_tempfile(): new function to handle an existing temporary file

2 messages, 2 authors, 2016-06-15 · open the first message on its own page

Re: [PATCH 07/14] register_tempfile(): new function to handle an existing temporary file

From: Junio C Hamano <hidden>
Date: 2016-06-15 23:05:15

Michael Haggerty [off-list ref] writes:
Allow an existing file to be registered with the tempfile-handling
infrastructure; in particular, arrange for it to be deleted on program
exit.

Signed-off-by: Michael Haggerty <redacted>
---
Hmph.  Where does such a tempfile that is not on list come from?

Puzzled, but let's read on---this could for example become an
internal implementation detail for create_tempfile().  Also I cannot
tell which one of register_tempfile() and register_tempfile_object()
I should be calling when updating the implementation of this API
from their names.
quoted hunk
diff --git a/tempfile.c b/tempfile.c
index 890075f..235fc85 100644
--- a/tempfile.c
+++ b/tempfile.c
@@ -82,6 +82,15 @@ int create_tempfile(struct tempfile *tempfile, const char *path)
 	return tempfile->fd;
 }
 
+void register_tempfile(struct tempfile *tempfile, const char *path)
+{
+	register_tempfile_object(tempfile, path);
+
+	strbuf_add_absolute_path(&tempfile->filename, path);
+	tempfile->owner = getpid();
+	tempfile->active = 1;
+}
+
 int mks_tempfile_sm(struct tempfile *tempfile,
 		    const char *template, int suffixlen, int mode)
 {
diff --git a/tempfile.h b/tempfile.h
index 6276156..18ff963 100644
--- a/tempfile.h
+++ b/tempfile.h
@@ -145,6 +145,14 @@ struct tempfile {
  */
 extern int create_tempfile(struct tempfile *tempfile, const char *path);
 
+/*
+ * Register an existing file as a tempfile, meaning that it will be
+ * deleted when the program exits. The tempfile is considered closed,
+ * but it can be worked with like any other closed tempfile (for
+ * example, it can be opened using reopen_tempfile()).
+ */
+extern void register_tempfile(struct tempfile *tempfile, const char *path);
+
 
 /*
  * mks_tempfile functions

Re: [PATCH 07/14] register_tempfile(): new function to handle an existing temporary file

From: Michael Haggerty <hidden>
Date: 2016-06-15 23:06:07

On 06/10/2015 07:55 PM, Junio C Hamano wrote:
Michael Haggerty [off-list ref] writes:
quoted
Allow an existing file to be registered with the tempfile-handling
infrastructure; in particular, arrange for it to be deleted on program
exit.

Signed-off-by: Michael Haggerty <redacted>
---
Hmph.  Where does such a tempfile that is not on list come from?
You saw the answer to your question later in the patch series, but for
the benefit of other readers:

This function will be useful to manage the lifetime of a file whose
creation is not as simple as open(); for example, if the file has to
itself be created using the lockfile API, or if it is not a regular file
(e.g., a socket). I will explain this better in the commit message in v2.
[...] Also I cannot
tell which one of register_tempfile() and register_tempfile_object()
I should be calling when updating the implementation of this API
from their names.
Good point. I will rename the latter to prepare_tempfile_object() and
add a docstring.

Michael

-- 
Michael Haggerty
mhagger@alum.mit.edu
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help