annotate lib/swig/swigwin-2.0.11/CCache/cleanup.c @ 2222:66bd74aa9f5e

smk video draw
author Ritor1
date Tue, 18 Feb 2014 19:43:54 +0600
parents b3009adc0e2f
children
rev   line source
1899
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1 /*
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2 Copyright (C) Andrew Tridgell 2002
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
3
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
4 This program is free software; you can redistribute it and/or modify
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
6 the Free Software Foundation; either version 2 of the License, or
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
7 (at your option) any later version.
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
8
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
12 GNU General Public License for more details.
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
13
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
15 along with this program; if not, write to the Free Software
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
17 */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
18 /*
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
19 functions to cleanup the cache directory when it gets too large
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
20 */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
21
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
22 #include "ccache.h"
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
23
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
24 static struct files {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
25 char *fname;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
26 time_t mtime;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
27 size_t size;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
28 } **files;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
29 static unsigned allocated;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
30 static unsigned num_files;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
31 static size_t total_size;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
32 static size_t total_files;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
33 static size_t size_threshold;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
34 static size_t files_threshold;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
35
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
36 /* file comparison function to try to delete the oldest files first */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
37 static int files_compare(struct files **f1, struct files **f2)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
38 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
39 if ((*f2)->mtime == (*f1)->mtime) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
40 return strcmp((*f2)->fname, (*f1)->fname);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
41 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
42 if ((*f2)->mtime > (*f1)->mtime) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
43 return -1;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
44 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
45 return 1;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
46 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
47
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
48 /* this builds the list of files in the cache */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
49 static void traverse_fn(const char *fname, struct stat *st)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
50 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
51 char *p;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
52
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
53 if (!S_ISREG(st->st_mode)) return;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
54
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
55 p = str_basename(fname);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
56 if (strcmp(p, "stats") == 0) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
57 free(p);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
58 return;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
59 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
60 free(p);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
61
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
62 if (num_files == allocated) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
63 allocated = 10000 + num_files*2;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
64 files = (struct files **)x_realloc(files,
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
65 sizeof(struct files *)*allocated);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
66 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
67
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
68 files[num_files] = (struct files *)x_malloc(sizeof(struct files));
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
69 files[num_files]->fname = x_strdup(fname);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
70 files[num_files]->mtime = st->st_mtime;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
71 files[num_files]->size = file_size(st) / 1024;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
72 total_size += files[num_files]->size;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
73 num_files++;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
74 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
75
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
76 /* sort the files we've found and delete the oldest ones until we are
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
77 below the thresholds */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
78 static void sort_and_clean(size_t minfiles)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
79 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
80 unsigned i;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
81 size_t adjusted_minfiles = minfiles;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
82
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
83 if (num_files > 1) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
84 /* sort in ascending data order */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
85 qsort(files, num_files, sizeof(struct files *),
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
86 (COMPAR_FN_T)files_compare);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
87 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
88 /* ensure newly cached files (minfiles) are kept - instead of matching
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
89 the filenames of those newly cached, a faster and simpler approach
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
90 assumes these are the most recent in the cache and if any other
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
91 cached files have an identical time stamp, they will also be kept -
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
92 this approach would not be needed if the cleanup was done at exit. */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
93 if (minfiles != 0 && minfiles < num_files) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
94 unsigned minfiles_index = num_files - minfiles;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
95 time_t minfiles_time = files[minfiles_index]->mtime;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
96 for (i=1; i<=minfiles_index; i++) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
97 if (files[minfiles_index-i]->mtime == minfiles_time)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
98 adjusted_minfiles++;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
99 else
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
100 break;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
101 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
102 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
103
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
104 /* delete enough files to bring us below the threshold */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
105 for (i=0;i<num_files; i++) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
106 if ((size_threshold==0 || total_size < size_threshold) &&
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
107 (files_threshold==0 || (num_files-i) < files_threshold)) break;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
108
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
109 if (adjusted_minfiles != 0 && num_files-i <= adjusted_minfiles)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
110 break;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
111
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
112 if (unlink(files[i]->fname) != 0 && errno != ENOENT) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
113 fprintf(stderr, "unlink %s - %s\n",
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
114 files[i]->fname, strerror(errno));
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
115 continue;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
116 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
117
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
118 total_size -= files[i]->size;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
119 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
120
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
121 total_files = num_files - i;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
122 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
123
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
124 /* cleanup in one cache subdir */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
125 void cleanup_dir(const char *dir, size_t maxfiles, size_t maxsize, size_t minfiles)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
126 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
127 unsigned i;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
128
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
129 size_threshold = maxsize * LIMIT_MULTIPLE;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
130 files_threshold = maxfiles * LIMIT_MULTIPLE;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
131
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
132 num_files = 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
133 total_size = 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
134
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
135 /* build a list of files */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
136 traverse(dir, traverse_fn);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
137
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
138 /* clean the cache */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
139 sort_and_clean(minfiles);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
140
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
141 stats_set_sizes(dir, total_files, total_size);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
142
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
143 /* free it up */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
144 for (i=0;i<num_files;i++) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
145 free(files[i]->fname);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
146 free(files[i]);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
147 files[i] = NULL;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
148 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
149 if (files) free(files);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
150 allocated = 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
151 files = NULL;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
152
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
153 num_files = 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
154 total_size = 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
155 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
156
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
157 /* cleanup in all cache subdirs */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
158 void cleanup_all(const char *dir)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
159 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
160 unsigned counters[STATS_END];
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
161 char *dname, *sfile;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
162 int i;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
163
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
164 for (i=0;i<=0xF;i++) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
165 x_asprintf(&dname, "%s/%1x", dir, i);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
166 x_asprintf(&sfile, "%s/%1x/stats", dir, i);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
167
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
168 memset(counters, 0, sizeof(counters));
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
169 stats_read(sfile, counters);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
170
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
171 cleanup_dir(dname,
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
172 counters[STATS_MAXFILES],
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
173 counters[STATS_MAXSIZE],
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
174 0);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
175 free(dname);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
176 free(sfile);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
177 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
178 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
179
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
180
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
181 /* traverse function for wiping files */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
182 static void wipe_fn(const char *fname, struct stat *st)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
183 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
184 char *p;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
185
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
186 if (!S_ISREG(st->st_mode)) return;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
187
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
188 p = str_basename(fname);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
189 if (strcmp(p, "stats") == 0) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
190 free(p);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
191 return;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
192 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
193 free(p);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
194
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
195 unlink(fname);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
196 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
197
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
198
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
199 /* wipe all cached files in all subdirs */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
200 void wipe_all(const char *dir)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
201 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
202 char *dname;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
203 int i;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
204
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
205 for (i=0;i<=0xF;i++) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
206 x_asprintf(&dname, "%s/%1x", dir, i);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
207 traverse(dir, wipe_fn);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
208 free(dname);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
209 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
210
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
211 /* and fix the counters */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
212 cleanup_all(dir);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
213 }