]>
Dogcows Code - chaz/tar/blob - src/unlink.c
3 Copyright 2009, 2013 Free Software Foundation, Inc.
5 This file is part of GNU tar.
7 GNU tar is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 GNU tar is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
24 struct deferred_unlink
26 struct deferred_unlink
*next
; /* Next unlink in the queue */
27 char *file_name
; /* Absolute name of the file to unlink */
28 bool is_dir
; /* True if file_name is a directory */
29 off_t records_written
; /* Number of records written when this
30 entry got added to the queue */
33 /* The unlink queue */
34 static struct deferred_unlink
*dunlink_head
, *dunlink_tail
;
36 /* Number of entries in the queue */
37 static size_t dunlink_count
;
39 /* List of entries available for allocation */
40 static struct deferred_unlink
*dunlink_avail
;
42 /* Delay (number of records written) between adding entry to the
43 list and its actual removal. */
44 static size_t deferred_unlink_delay
= 0;
46 static struct deferred_unlink
*
49 struct deferred_unlink
*p
;
53 dunlink_avail
= p
->next
;
57 p
= xmalloc (sizeof (*p
));
62 dunlink_reclaim (struct deferred_unlink
*p
)
65 p
->next
= dunlink_avail
;
70 flush_deferred_unlinks (bool force
)
72 struct deferred_unlink
*p
, *prev
= NULL
;
74 for (p
= dunlink_head
; p
; )
76 struct deferred_unlink
*next
= p
->next
;
78 || records_written
> p
->records_written
+ deferred_unlink_delay
)
82 if (unlinkat (chdir_fd
, p
->file_name
, AT_REMOVEDIR
) != 0)
87 /* nothing to worry about */
92 /* Keep the record in list, in the hope we'll
93 be able to remove it later */
100 rmdir_error (p
->file_name
);
106 if (unlinkat (chdir_fd
, p
->file_name
, 0) != 0 && errno
!= ENOENT
)
107 unlink_error (p
->file_name
);
128 finish_deferred_unlinks (void)
130 flush_deferred_unlinks (true);
131 while (dunlink_avail
)
133 struct deferred_unlink
*next
= dunlink_avail
->next
;
134 free (dunlink_avail
);
135 dunlink_avail
= next
;
140 queue_deferred_unlink (const char *name
, bool is_dir
)
142 struct deferred_unlink
*p
;
145 && records_written
> dunlink_head
->records_written
+ deferred_unlink_delay
)
146 flush_deferred_unlinks (false);
148 p
= dunlink_alloc ();
150 p
->file_name
= normalize_filename (name
);
152 p
->records_written
= records_written
;
155 dunlink_tail
->next
= p
;
This page took 0.042871 seconds and 4 git commands to generate.