14
14
*
15
15
* The possible states of a `tempfile` object are as follows:
16
16
*
17
- * - Uninitialized. In this state the object's `on_list` field must be
18
- * zero but the rest of its contents need not be initialized. As
19
- * soon as the object is used in any way, it is irrevocably
20
- * registered in `tempfile_list`, and `on_list` is set.
17
+ * - Inactive/unallocated. The only way to get a tempfile is via a creation
18
+ * function like create_tempfile(). Once allocated, the tempfile is on the
19
+ * global tempfile_list and considered active.
21
20
*
22
21
* - Active, file open (after `create_tempfile()` or
23
22
* `reopen_tempfile()`). In this state:
24
23
*
25
24
* - the temporary file exists
26
- * - `active` is set
27
25
* - `filename` holds the filename of the temporary file
28
26
* - `fd` holds a file descriptor open for writing to it
29
27
* - `fp` holds a pointer to an open `FILE` object if and only if
35
33
* `fd` is -1, and `fp` is `NULL`.
36
34
*
37
35
* - Inactive (after `delete_tempfile()`, `rename_tempfile()`, or a
38
- * failed attempt to create a temporary file). In this state:
39
- *
40
- * - `active` is unset
41
- * - `filename` is empty (usually, though there are transitory
42
- * states in which this condition doesn't hold). Client code should
43
- * *not* rely on the filename being empty in this state.
44
- * - `fd` is -1 and `fp` is `NULL`
45
- * - the object is removed from `tempfile_list` (but could be used again)
36
+ * failed attempt to create a temporary file). The struct is removed from
37
+ * the global tempfile_list and deallocated.
46
38
*
47
39
* A temporary file is owned by the process that created it. The
48
40
* `tempfile` has an `owner` field that records the owner's PID. This
@@ -86,8 +78,6 @@ static void remove_tempfiles(int in_signal_handler)
86
78
else
87
79
unlink_or_warn (p -> filename .buf );
88
80
remove_template_directory (p , in_signal_handler );
89
-
90
- p -> active = 0 ;
91
81
}
92
82
}
93
83
@@ -108,7 +98,6 @@ static struct tempfile *new_tempfile(void)
108
98
struct tempfile * tempfile = xmalloc (sizeof (* tempfile ));
109
99
tempfile -> fd = -1 ;
110
100
tempfile -> fp = NULL ;
111
- tempfile -> active = 0 ;
112
101
tempfile -> owner = 0 ;
113
102
INIT_LIST_HEAD (& tempfile -> list );
114
103
strbuf_init (& tempfile -> filename , 0 );
@@ -120,9 +109,6 @@ static void activate_tempfile(struct tempfile *tempfile)
120
109
{
121
110
static int initialized ;
122
111
123
- if (is_tempfile_active (tempfile ))
124
- BUG ("activate_tempfile called for active object" );
125
-
126
112
if (!initialized ) {
127
113
sigchain_push_common (remove_tempfiles_on_signal );
128
114
atexit (remove_tempfiles_on_exit );
@@ -131,15 +117,13 @@ static void activate_tempfile(struct tempfile *tempfile)
131
117
132
118
volatile_list_add (& tempfile -> list , & tempfile_list );
133
119
tempfile -> owner = getpid ();
134
- tempfile -> active = 1 ;
135
120
}
136
121
137
122
static void deactivate_tempfile (struct tempfile * tempfile )
138
123
{
139
- tempfile -> active = 0 ;
124
+ volatile_list_del ( & tempfile -> list ) ;
140
125
strbuf_release (& tempfile -> filename );
141
126
free (tempfile -> directory );
142
- volatile_list_del (& tempfile -> list );
143
127
free (tempfile );
144
128
}
145
129
0 commit comments