1 | /* libmondo-filelist.c
|
---|
2 | $Id: libmondo-filelist.c 1967 2008-05-29 15:40:05Z bruno $
|
---|
3 |
|
---|
4 | - for subroutines which manipulate the filelist
|
---|
5 |
|
---|
6 |
|
---|
7 | 01/11/2005
|
---|
8 | - change time_of_last_full_backup = to st_mtime to allow manipulation of
|
---|
9 | - /var/cache/mondo-archive/difflevel.0
|
---|
10 | - Conor Daly <conor.daly@met.ie>
|
---|
11 |
|
---|
12 | 10/01
|
---|
13 | - don't try to sort non-existent file; return 0 instead
|
---|
14 |
|
---|
15 | 09/14
|
---|
16 | - dropped 'sort -o' (busybox doesn't support); use 'sort > ' instead
|
---|
17 |
|
---|
18 | 08/02
|
---|
19 | - add \ in front of [, ], ? or * when generating filelist subset
|
---|
20 |
|
---|
21 | 07/27
|
---|
22 | - sort filelists after creating them
|
---|
23 |
|
---|
24 | 07/14
|
---|
25 | - disabled ACL, xattr stuff; moved it to libmondo-archive.c
|
---|
26 | - max sane size for a file is now 32MB
|
---|
27 |
|
---|
28 | 07/10
|
---|
29 | - added ACL and xattr support for afio users
|
---|
30 |
|
---|
31 | 07/05
|
---|
32 | - exclude /dev/shm from backup (Roberto Alsina)
|
---|
33 |
|
---|
34 | 06/09
|
---|
35 | - exclude /media/floppy or SuSE 9.1 freezes :(
|
---|
36 |
|
---|
37 | 01/18/2004
|
---|
38 | - exclude /sys as well as /proc
|
---|
39 |
|
---|
40 | 10/18/2003
|
---|
41 | - load_filelist() --- make sure you add the paths
|
---|
42 | leading to the file, e.g. if you add /usr/lib/thingy.so
|
---|
43 | then add /usr, /usr/lib first
|
---|
44 | - rewritten load_filelist(), save_filelist(),
|
---|
45 | - add_string_at_node(), find_string_at_node(),
|
---|
46 | - save_filelist_entries_in_common()
|
---|
47 |
|
---|
48 | 09/27
|
---|
49 | - line 1269 had one too many '%s's
|
---|
50 |
|
---|
51 | 09/26
|
---|
52 | - fix newt* to be enclosed in #ifndef _XWIN
|
---|
53 | - added superior progress display to mondo_makefilelist()
|
---|
54 |
|
---|
55 | 09/18
|
---|
56 | - call locate w/ 2> /dev/null at end of str
|
---|
57 |
|
---|
58 | 09/16
|
---|
59 | - replaced mondo-makefilelist with C subroutine
|
---|
60 |
|
---|
61 | 06/06
|
---|
62 | - fixed silly bug in load_filelist() which stopped
|
---|
63 | funny German filenames from being handled properly
|
---|
64 |
|
---|
65 | 05/19
|
---|
66 | - misc clean-up (Steve Hindle)
|
---|
67 |
|
---|
68 | 05/04
|
---|
69 | - added Herman Kuster's multi-level bkp patch
|
---|
70 |
|
---|
71 | 04/26
|
---|
72 | - maximum max_set_size_for_a_file = maxsetsizeK*2
|
---|
73 | - maximum is also 32MB
|
---|
74 |
|
---|
75 | 04/24
|
---|
76 | - added lots of assert()'s and log_OS_error()'s
|
---|
77 |
|
---|
78 | 04/22
|
---|
79 | - added lots of asserts() and log_OS_errors()'s
|
---|
80 |
|
---|
81 | 04/07
|
---|
82 | - cleaned up code a bit
|
---|
83 |
|
---|
84 | 04/04
|
---|
85 | - max_sane_size_for_a_file = maxsetsizeK*2 (was *8)
|
---|
86 |
|
---|
87 | 01/02/2003
|
---|
88 | - tell mondo-makefilelist that it's a custom catalog (if it is)
|
---|
89 |
|
---|
90 | 10/01 - 10/31/2002
|
---|
91 | - don't make large .bz2 or .tbz files into biggiefiles
|
---|
92 | - max_sane_size_for_a_file = maxsetsizeK*8, or 64MB
|
---|
93 | ...whichever is smaller
|
---|
94 |
|
---|
95 | 08/01 - 08/31
|
---|
96 | - if last filelist is <=2 bytes long then delete it
|
---|
97 | - max_sane_size_for_a_file = maxsetsizeK
|
---|
98 | (was SLICESIZE*4 or something)
|
---|
99 | - cleaned up some log_it() calls
|
---|
100 |
|
---|
101 | 07/26
|
---|
102 | - started
|
---|
103 | */
|
---|
104 |
|
---|
105 | /**
|
---|
106 | * @file
|
---|
107 | * Functions which create, chop, and edit the filelist.
|
---|
108 | */
|
---|
109 |
|
---|
110 | #include "my-stuff.h"
|
---|
111 | #include "mondostructures.h"
|
---|
112 | #include "lib-common-externs.h"
|
---|
113 | #include "libmondo-filelist.h"
|
---|
114 | #include "libmondo-string-EXT.h"
|
---|
115 | #include "libmondo-files-EXT.h"
|
---|
116 | #include "libmondo-fork-EXT.h"
|
---|
117 | #include "libmondo-gui-EXT.h"
|
---|
118 | #include "libmondo-tools-EXT.h"
|
---|
119 | #include "mr_string.h"
|
---|
120 |
|
---|
121 | #include <time.h>
|
---|
122 | #include <stdio.h>
|
---|
123 | #include <sys/types.h>
|
---|
124 | #include <sys/stat.h>
|
---|
125 | #include <dirent.h>
|
---|
126 | #include <errno.h>
|
---|
127 | #include <stdio.h>
|
---|
128 |
|
---|
129 |
|
---|
130 | /**
|
---|
131 | * The maximum depth of directories to put in the skeleton filelist.
|
---|
132 | * This is a balance between performance and a good progress indicator.
|
---|
133 | */
|
---|
134 | #define MAX_SKEL_DEPTH 3
|
---|
135 |
|
---|
136 |
|
---|
137 | extern ssize_t getline(char **lineptr, size_t * n, FILE * stream);
|
---|
138 | extern char *MONDO_LOGFILE;
|
---|
139 |
|
---|
140 | /* Reference to global bkpinfo */
|
---|
141 | extern struct s_bkpinfo *bkpinfo;
|
---|
142 |
|
---|
143 |
|
---|
144 | int mondo_makefilelist(char *logfile, char *tmpdir, char *scratchdir,
|
---|
145 | char *include_paths, char *excp, int differential,
|
---|
146 | char *userdef_filelist);
|
---|
147 |
|
---|
148 |
|
---|
149 | /*@unused@*/
|
---|
150 | //static char cvsid[] = "$Id: libmondo-filelist.c 1967 2008-05-29 15:40:05Z bruno $";
|
---|
151 |
|
---|
152 | /**
|
---|
153 | * Number of lines in the filelist last loaded.
|
---|
154 | * @warning This implies that two filesets cannot be loaded at once.
|
---|
155 | * @ingroup globalGroup
|
---|
156 | */
|
---|
157 | long g_original_noof_lines_in_filelist = 0;
|
---|
158 |
|
---|
159 | /**
|
---|
160 | * Number of filesets in the current backup.
|
---|
161 | * @ingroup globalGroup
|
---|
162 | */
|
---|
163 | long g_noof_sets = 0;
|
---|
164 |
|
---|
165 | extern bool g_text_mode;
|
---|
166 | extern newtComponent g_progressForm;
|
---|
167 | extern int g_currentY;
|
---|
168 | extern int g_noof_rows;
|
---|
169 |
|
---|
170 | extern char *g_getfacl;
|
---|
171 | extern char *g_getfattr;
|
---|
172 |
|
---|
173 |
|
---|
174 |
|
---|
175 | /**
|
---|
176 | * @addtogroup filelistGroup
|
---|
177 | * @{
|
---|
178 | */
|
---|
179 | /**
|
---|
180 | * Call chop_filelist() to chop the filelist into sets.
|
---|
181 | * @param bkpinfo The backup information structure. Fields used:
|
---|
182 | * - @c bkpinfo->image_devs
|
---|
183 | * - @c bkpinfo->optimal_set_size
|
---|
184 | * - @c bkpinfo->scratchdir
|
---|
185 | * - @c bkpinfo->tmpdir
|
---|
186 | * @see chop_filelist
|
---|
187 | */
|
---|
188 | int call_filelist_chopper()
|
---|
189 | {
|
---|
190 | /*@ buffers *********************** */
|
---|
191 | char *dev;
|
---|
192 | char *filelist;
|
---|
193 | char *tempfile;
|
---|
194 | char *cksumlist;
|
---|
195 | char *tmp;
|
---|
196 | long noof_sets;
|
---|
197 |
|
---|
198 | /*@ pointers ********************** */
|
---|
199 | char *ptr;
|
---|
200 | FILE *fout;
|
---|
201 |
|
---|
202 | /*@ int *************************** */
|
---|
203 | int i, retval = 0;
|
---|
204 |
|
---|
205 | malloc_string(dev);
|
---|
206 | malloc_string(filelist);
|
---|
207 | malloc_string(tempfile);
|
---|
208 | malloc_string(cksumlist);
|
---|
209 | malloc_string(tmp);
|
---|
210 | mvaddstr_and_log_it(g_currentY, 0, "Dividing filelist into sets");
|
---|
211 |
|
---|
212 | log_to_screen("Dividing filelist into sets. Please wait.");
|
---|
213 | i = 0;
|
---|
214 | sprintf(filelist, "%s/archives/filelist.full", bkpinfo->scratchdir);
|
---|
215 | sprintf(cksumlist, "%s/cklist.full", bkpinfo->tmpdir);
|
---|
216 | if (!does_file_exist(filelist)) {
|
---|
217 | log_it("filelist %s not found", filelist);
|
---|
218 | fatal_error("call_filelist_chopper() -- filelist not found!");
|
---|
219 | }
|
---|
220 |
|
---|
221 | noof_sets =
|
---|
222 | chop_filelist(filelist, bkpinfo->tmpdir,
|
---|
223 | bkpinfo->optimal_set_size);
|
---|
224 | estimate_noof_media_required(noof_sets); // for cosmetic purposes
|
---|
225 |
|
---|
226 | sprintf(tempfile, "%s/biggielist.txt", bkpinfo->tmpdir);
|
---|
227 | if (!(fout = fopen(tempfile, "a"))) {
|
---|
228 | log_OS_error("Cannot append to biggielist");
|
---|
229 | retval++;
|
---|
230 | goto end_of_func;
|
---|
231 | }
|
---|
232 | log_it(bkpinfo->image_devs);
|
---|
233 |
|
---|
234 | ptr = bkpinfo->image_devs;
|
---|
235 |
|
---|
236 | while (ptr && *ptr) {
|
---|
237 | strcpy(dev, ptr);
|
---|
238 | log_it("Examining imagedev %s", dev);
|
---|
239 | for (i = 0; i < (int) strlen(dev) && dev[i] != ' '; i++);
|
---|
240 | dev[i] = '\0';
|
---|
241 | if (!strlen(dev)) {
|
---|
242 | continue;
|
---|
243 | }
|
---|
244 | fprintf(fout, "%s\n", dev);
|
---|
245 | log_it("Adding '%s' to biggielist", dev);
|
---|
246 | if ((ptr = strchr(ptr, ' '))) {
|
---|
247 | ptr++;
|
---|
248 | }
|
---|
249 | }
|
---|
250 | paranoid_fclose(fout);
|
---|
251 | mvaddstr_and_log_it(g_currentY++, 74, "Done.");
|
---|
252 |
|
---|
253 | end_of_func:
|
---|
254 | paranoid_free(filelist);
|
---|
255 | paranoid_free(tempfile);
|
---|
256 | paranoid_free(cksumlist);
|
---|
257 | paranoid_free(dev);
|
---|
258 | paranoid_free(tmp);
|
---|
259 | return (retval);
|
---|
260 | }
|
---|
261 |
|
---|
262 |
|
---|
263 |
|
---|
264 | int sort_file(char *orig_fname)
|
---|
265 | {
|
---|
266 | char *tmp_fname;
|
---|
267 | char *command;
|
---|
268 | int retval = 0;
|
---|
269 |
|
---|
270 | log_msg(5, "Sorting file %s", orig_fname);
|
---|
271 | malloc_string(tmp_fname);
|
---|
272 | malloc_string(command);
|
---|
273 | sprintf(tmp_fname, "%s/sortfile", bkpinfo->tmpdir);
|
---|
274 |
|
---|
275 | if (!does_file_exist(orig_fname)) {
|
---|
276 | log_msg(2, "file %s empty", orig_fname);
|
---|
277 | return (0);
|
---|
278 | } // no sense in trying to sort an empty file
|
---|
279 |
|
---|
280 | sprintf(command, "sort %s > %s 2>> %s", orig_fname, tmp_fname,
|
---|
281 | MONDO_LOGFILE);
|
---|
282 | retval = system(command);
|
---|
283 | if (retval) {
|
---|
284 | log_msg(2, "Failed to sort %s - oh dear", orig_fname);
|
---|
285 | } else {
|
---|
286 | log_msg(5, "Sorted %s --> %s OK. Copying it back to %s now",
|
---|
287 | orig_fname, tmp_fname, orig_fname);
|
---|
288 | sprintf(command, "mv -f %s %s", tmp_fname, orig_fname);
|
---|
289 | retval += run_program_and_log_output(command, 5);
|
---|
290 | if (retval) {
|
---|
291 | log_msg(2, "Failed to copy %s back to %s - oh dear", tmp_fname,
|
---|
292 | orig_fname);
|
---|
293 | } else {
|
---|
294 | log_msg(5, "%s was sorted OK.", orig_fname);
|
---|
295 | }
|
---|
296 | }
|
---|
297 | paranoid_free(tmp_fname);
|
---|
298 | paranoid_free(command);
|
---|
299 | log_msg(5, "Finished sorting file %s", orig_fname);
|
---|
300 | return (retval);
|
---|
301 | }
|
---|
302 |
|
---|
303 |
|
---|
304 |
|
---|
305 | /**
|
---|
306 | * Chop the filelist into sets.
|
---|
307 | * Each fileset is a list of files whose total (uncompressed) size is usually
|
---|
308 | * about X KB. Files bigger than 8X KB are placed in a "biggielist"; they will
|
---|
309 | * be sliced and compressed separately from the regular files.
|
---|
310 | *
|
---|
311 | * @param filelist The big filelist (filelist.full) to chop up.
|
---|
312 | * @param outdir The directory to place the files (filelist.N where N is
|
---|
313 | * an integer, biggielist.txt, and LAST-FILELIST-NUMBER) created
|
---|
314 | * @param maxsetsizeK Optimal size of a fileset (X above).
|
---|
315 | * @return number of errors encountered (0 for success).
|
---|
316 | */
|
---|
317 | int chop_filelist(char *filelist, char *outdir, long maxsetsizeK)
|
---|
318 | {
|
---|
319 | /*@ long ****************************************/
|
---|
320 | long lino = 0;
|
---|
321 | long max_sane_size_for_a_file;
|
---|
322 | long curr_set_size;
|
---|
323 | long noof_lines;
|
---|
324 | long siz;
|
---|
325 |
|
---|
326 | /*@ int **************************************** */
|
---|
327 | int i;
|
---|
328 | long curr_set_no;
|
---|
329 |
|
---|
330 | /*@ buffers ************************************* */
|
---|
331 | char *outfname;
|
---|
332 | char *biggie_fname;
|
---|
333 | char *incoming;
|
---|
334 | char *tmp;
|
---|
335 | char *acl_fname;
|
---|
336 | char *xattr_fname;
|
---|
337 |
|
---|
338 | /*@ pointers *********************************** */
|
---|
339 | FILE *fin;
|
---|
340 | FILE *fout;
|
---|
341 | FILE *fbig;
|
---|
342 |
|
---|
343 | /*@ structures ********************************* */
|
---|
344 | struct stat buf;
|
---|
345 | int err = 0;
|
---|
346 |
|
---|
347 | malloc_string(outfname);
|
---|
348 | malloc_string(biggie_fname);
|
---|
349 | incoming = malloc(MAX_STR_LEN * 2);
|
---|
350 | malloc_string(tmp);
|
---|
351 | malloc_string(acl_fname);
|
---|
352 | malloc_string(xattr_fname);
|
---|
353 |
|
---|
354 | assert_string_is_neither_NULL_nor_zerolength(filelist);
|
---|
355 | assert_string_is_neither_NULL_nor_zerolength(outdir);
|
---|
356 | assert(maxsetsizeK > 0);
|
---|
357 |
|
---|
358 | max_sane_size_for_a_file = 64L * 1024L;
|
---|
359 | // max_sane_size_for_a_file = maxsetsizeK*2;
|
---|
360 | // if (max_sane_size_for_a_file > 32*1024)
|
---|
361 | // { max_sane_size_for_a_file = 32*1024; }
|
---|
362 |
|
---|
363 | log_it("filelist=%s;", filelist);
|
---|
364 | open_evalcall_form("Dividing filelist into sets");
|
---|
365 | noof_lines = count_lines_in_file(filelist);
|
---|
366 | if (!(fin = fopen(filelist, "r"))) {
|
---|
367 | log_OS_error("Cannot openin filelist");
|
---|
368 | return (0);
|
---|
369 | }
|
---|
370 | curr_set_no = 0;
|
---|
371 | curr_set_size = 0;
|
---|
372 | sprintf(outfname, "%s/filelist.%ld", outdir, curr_set_no);
|
---|
373 | sprintf(biggie_fname, "%s/biggielist.txt", outdir);
|
---|
374 | log_it("outfname=%s; biggie_fname=%s", outfname, biggie_fname);
|
---|
375 | if (!(fbig = fopen(biggie_fname, "w"))) {
|
---|
376 | log_OS_error("Cannot openout biggie_fname");
|
---|
377 | err++;
|
---|
378 | goto end_of_func;
|
---|
379 | }
|
---|
380 | if (!(fout = fopen(outfname, "w"))) {
|
---|
381 | log_OS_error("Cannot openout outfname");
|
---|
382 | err++;
|
---|
383 | goto end_of_func;
|
---|
384 | }
|
---|
385 | (void) fgets(incoming, MAX_STR_LEN * 2 - 1, fin);
|
---|
386 | while (!feof(fin)) {
|
---|
387 | lino++;
|
---|
388 | i = strlen(incoming) - 1;
|
---|
389 | if (i < 0) {
|
---|
390 | i = 0;
|
---|
391 | }
|
---|
392 | if (i > MAX_STR_LEN - 1) {
|
---|
393 | incoming[MAX_STR_LEN - 30] = '\0';
|
---|
394 | log_msg(1, "Warning - truncating file %s's name", incoming);
|
---|
395 | err++;
|
---|
396 | }
|
---|
397 | if (incoming[i] < 32) {
|
---|
398 | incoming[i] = '\0';
|
---|
399 | }
|
---|
400 | if (!strncmp(incoming, "/dev/", 5)) {
|
---|
401 | siz = 1;
|
---|
402 | } else if (lstat(incoming, &buf) != 0) {
|
---|
403 | siz = 0;
|
---|
404 | } else {
|
---|
405 | siz = (long) (buf.st_size >> 10);
|
---|
406 | }
|
---|
407 | if (siz > max_sane_size_for_a_file)
|
---|
408 | // && strcmp(incoming+strlen(incoming)-4, ".bz2") && strcmp(incoming+strlen(incoming)-4, ".tbz"))
|
---|
409 | {
|
---|
410 | fprintf(fbig, "%s\n", incoming);
|
---|
411 | } else {
|
---|
412 | curr_set_size += siz;
|
---|
413 | fprintf(fout, "%s\n", incoming);
|
---|
414 | if (curr_set_size > maxsetsizeK) {
|
---|
415 | paranoid_fclose(fout);
|
---|
416 | sort_file(outfname);
|
---|
417 | curr_set_no++;
|
---|
418 | curr_set_size = 0;
|
---|
419 | sprintf(outfname, "%s/filelist.%ld", outdir, curr_set_no);
|
---|
420 | if (!(fout = fopen(outfname, "w"))) {
|
---|
421 | log_OS_error("Unable to openout outfname");
|
---|
422 | err++;
|
---|
423 | goto end_of_func;
|
---|
424 | }
|
---|
425 | sprintf(tmp, "Fileset #%ld chopped ", curr_set_no - 1);
|
---|
426 | update_evalcall_form((int) (lino * 100 / noof_lines));
|
---|
427 | /* if (!g_text_mode) {newtDrawRootText(0,22,tmp);newtRefresh();} else {log_it(tmp);} */
|
---|
428 | }
|
---|
429 | }
|
---|
430 | (void) fgets(incoming, MAX_STR_LEN * 2 - 1, fin);
|
---|
431 | }
|
---|
432 | paranoid_fclose(fin);
|
---|
433 | paranoid_fclose(fout);
|
---|
434 | paranoid_fclose(fbig);
|
---|
435 |
|
---|
436 | if (length_of_file(outfname) <= 2) {
|
---|
437 | unlink(outfname);
|
---|
438 | g_noof_sets--;
|
---|
439 | }
|
---|
440 | g_noof_sets = curr_set_no;
|
---|
441 | sort_file(outfname);
|
---|
442 | sort_file(biggie_fname);
|
---|
443 | sprintf(outfname, "%s/LAST-FILELIST-NUMBER", outdir);
|
---|
444 | sprintf(tmp, "%ld", curr_set_no);
|
---|
445 | if (write_one_liner_data_file(outfname, tmp)) {
|
---|
446 | log_OS_error
|
---|
447 | ("Unable to echo write one-liner to LAST-FILELIST-NUMBER");
|
---|
448 | err = 1;
|
---|
449 | }
|
---|
450 | if (curr_set_no == 0) {
|
---|
451 | sprintf(tmp, "Only one fileset. Fine.");
|
---|
452 | } else {
|
---|
453 | sprintf(tmp, "Filelist divided into %ld sets", curr_set_no + 1);
|
---|
454 | }
|
---|
455 | log_msg(1, tmp);
|
---|
456 | close_evalcall_form();
|
---|
457 | /* This is to work around an obscure bug in Newt; open a form, close it,
|
---|
458 | carry on... I don't know why it works but it works. If you don't do this
|
---|
459 | then update_progress_form() won't show the "time taken / time remaining"
|
---|
460 | line. The bug only crops up AFTER the call to chop_filelist(). Weird. */
|
---|
461 | #ifndef _XWIN
|
---|
462 | if (!g_text_mode) {
|
---|
463 | open_progress_form("", "", "", "", 100);
|
---|
464 | newtPopHelpLine();
|
---|
465 | newtFormDestroy(g_progressForm);
|
---|
466 | newtPopWindow();
|
---|
467 | }
|
---|
468 | #endif
|
---|
469 | end_of_func:
|
---|
470 | paranoid_free(outfname);
|
---|
471 | paranoid_free(biggie_fname);
|
---|
472 | paranoid_free(incoming);
|
---|
473 | paranoid_free(tmp);
|
---|
474 | paranoid_free(acl_fname);
|
---|
475 | paranoid_free(xattr_fname);
|
---|
476 | return (err ? 0 : curr_set_no + 1);
|
---|
477 | }
|
---|
478 |
|
---|
479 |
|
---|
480 |
|
---|
481 |
|
---|
482 |
|
---|
483 | /**
|
---|
484 | * Free all the memory used by a filelist structure.
|
---|
485 | * Since this may take a long time for large filelists, a progress bar will be displayed.
|
---|
486 | * @param filelist The filelist to free.
|
---|
487 | */
|
---|
488 | void free_filelist(struct s_node *filelist)
|
---|
489 | {
|
---|
490 | /*@ int's ******************************************************* */
|
---|
491 | static int depth = 0;
|
---|
492 | int percentage;
|
---|
493 |
|
---|
494 | /*@ long's ****************************************************** */
|
---|
495 | static long i = 0;
|
---|
496 |
|
---|
497 | /*@ end vars **************************************************** */
|
---|
498 |
|
---|
499 | assert(filelist != NULL);
|
---|
500 | if (depth == 0) {
|
---|
501 | open_evalcall_form("Freeing memory");
|
---|
502 | log_to_screen("Freeing memory formerly occupied by filelist");
|
---|
503 | }
|
---|
504 | depth++;
|
---|
505 |
|
---|
506 | if (filelist->ch == '\0') {
|
---|
507 | if (!(i++ % 1111)) {
|
---|
508 | percentage =
|
---|
509 | (int) (i * 100 / g_original_noof_lines_in_filelist);
|
---|
510 | update_evalcall_form(percentage);
|
---|
511 |
|
---|
512 | }
|
---|
513 | }
|
---|
514 |
|
---|
515 | if (filelist->right) {
|
---|
516 | free_filelist(filelist->right);
|
---|
517 | filelist->right = NULL;
|
---|
518 | }
|
---|
519 | if (filelist->down) {
|
---|
520 | /* if (!(i++ %39999)) { update_evalcall_form(0); } */
|
---|
521 | free_filelist(filelist->down);
|
---|
522 | filelist->down = NULL;
|
---|
523 | }
|
---|
524 | filelist->ch = '\0';
|
---|
525 | paranoid_free(filelist);
|
---|
526 | depth--;
|
---|
527 | if (depth == 0) {
|
---|
528 | close_evalcall_form();
|
---|
529 | log_it("Finished freeing memory");
|
---|
530 | }
|
---|
531 | }
|
---|
532 |
|
---|
533 |
|
---|
534 | int call_exe_and_pipe_output_to_fd(char *syscall, FILE * pout)
|
---|
535 | {
|
---|
536 | FILE *pattr;
|
---|
537 | char *tmp;
|
---|
538 | pattr = popen(syscall, "r");
|
---|
539 | if (!pattr) {
|
---|
540 | log_msg(1, "Failed to open fattr() %s", syscall);
|
---|
541 | return (1);
|
---|
542 | }
|
---|
543 | if (feof(pattr)) {
|
---|
544 | log_msg(1, "Failed to call fattr() %s", syscall);
|
---|
545 | paranoid_pclose(pattr);
|
---|
546 | return (2);
|
---|
547 | }
|
---|
548 | malloc_string(tmp);
|
---|
549 | for (fgets(tmp, MAX_STR_LEN, pattr); !feof(pattr);
|
---|
550 | fgets(tmp, MAX_STR_LEN, pattr)) {
|
---|
551 | fputs(tmp, pout);
|
---|
552 | }
|
---|
553 | paranoid_pclose(pattr);
|
---|
554 | paranoid_free(tmp);
|
---|
555 | return (0);
|
---|
556 | }
|
---|
557 |
|
---|
558 |
|
---|
559 |
|
---|
560 | int gen_aux_list(char *filelist, char *syscall_sprintf,
|
---|
561 | char *auxlist_fname)
|
---|
562 | {
|
---|
563 | FILE *fin;
|
---|
564 | FILE *pout;
|
---|
565 | char *pout_command;
|
---|
566 | char *syscall;
|
---|
567 | char *file_to_analyze;
|
---|
568 | char *strtmp = NULL;
|
---|
569 | char *tmp = NULL;
|
---|
570 | int i;
|
---|
571 |
|
---|
572 | if (!(fin = fopen(filelist, "r"))) {
|
---|
573 | log_msg(1, "Cannot openin filelist %s", filelist);
|
---|
574 | return (1);
|
---|
575 | }
|
---|
576 | malloc_string(pout_command);
|
---|
577 | sprintf(pout_command, "gzip -c1 > %s", auxlist_fname);
|
---|
578 | if (!(pout = popen(pout_command, "w"))) {
|
---|
579 | log_msg(1, "Cannot openout auxlist_fname %s", auxlist_fname);
|
---|
580 | fclose(fin);
|
---|
581 | paranoid_free(pout_command);
|
---|
582 | return (4);
|
---|
583 | }
|
---|
584 | malloc_string(file_to_analyze);
|
---|
585 | for (fgets(file_to_analyze, MAX_STR_LEN, fin); !feof(fin);
|
---|
586 | fgets(file_to_analyze, MAX_STR_LEN, fin)) {
|
---|
587 | i = strlen(file_to_analyze);
|
---|
588 | if (i > 0 && file_to_analyze[i - 1] < 32) {
|
---|
589 | file_to_analyze[i - 1] = '\0';
|
---|
590 | }
|
---|
591 | log_msg(8, "Analyzing %s", file_to_analyze);
|
---|
592 | tmp = mr_stresc(file_to_analyze, "`$\\\"", '\\');
|
---|
593 | asprintf(&strtmp, syscall_sprintf, tmp);
|
---|
594 | paranoid_free(tmp);
|
---|
595 | asprintf(&syscall, "%s 2>> /dev/null", strtmp); // " MONDO_LOGFILE);
|
---|
596 | paranoid_free(strtmp);
|
---|
597 | call_exe_and_pipe_output_to_fd(syscall, pout);
|
---|
598 | paranoid_free(syscall);
|
---|
599 | }
|
---|
600 | paranoid_fclose(fin);
|
---|
601 | paranoid_pclose(pout);
|
---|
602 | paranoid_free(file_to_analyze);
|
---|
603 | paranoid_free(pout_command);
|
---|
604 | return (0);
|
---|
605 | }
|
---|
606 |
|
---|
607 |
|
---|
608 | int get_acl_list(char *filelist, char *facl_fname)
|
---|
609 | {
|
---|
610 | char *command;
|
---|
611 | int retval = 0;
|
---|
612 |
|
---|
613 | if (g_getfacl != NULL) {
|
---|
614 | malloc_string(command);
|
---|
615 | sprintf(command, "touch %s", facl_fname);
|
---|
616 | run_program_and_log_output(command, 8);
|
---|
617 | // sort_file(filelist); // FIXME - filelist chopper sorts, so this isn't necessary
|
---|
618 | sprintf(command,
|
---|
619 | "getfacl --all-effective -P %s 2>> %s | gzip -c1 > %s 2>> %s",
|
---|
620 | filelist, MONDO_LOGFILE, facl_fname, MONDO_LOGFILE);
|
---|
621 | iamhere(command);
|
---|
622 | retval = system(command);
|
---|
623 | paranoid_free(command);
|
---|
624 | }
|
---|
625 | return (retval);
|
---|
626 | }
|
---|
627 |
|
---|
628 |
|
---|
629 | int get_fattr_list(char *filelist, char *fattr_fname)
|
---|
630 | {
|
---|
631 | char *command;
|
---|
632 | int retval = 0;
|
---|
633 |
|
---|
634 | if (g_getfattr != NULL) {
|
---|
635 | malloc_string(command);
|
---|
636 | sprintf(command, "touch %s", fattr_fname);
|
---|
637 | run_program_and_log_output(command, 8);
|
---|
638 | paranoid_free(command);
|
---|
639 | // sort_file(filelist); // FIXME - filelist chopper sorts, so this isn't necessary
|
---|
640 | retval =
|
---|
641 | gen_aux_list(filelist, "getfattr --en=hex -P -d \"%s\"",
|
---|
642 | fattr_fname);
|
---|
643 | }
|
---|
644 | return (retval);
|
---|
645 | }
|
---|
646 |
|
---|
647 |
|
---|
648 | int set_EXAT_list(char *orig_msklist, char *original_exat_fname,
|
---|
649 | char *executable)
|
---|
650 | {
|
---|
651 | const int my_depth = 8;
|
---|
652 | char *command, *syscall_pin, *syscall_pout, *incoming;
|
---|
653 | char *current_subset_file, *current_master_file, *masklist;
|
---|
654 | int retval = 0;
|
---|
655 | int i;
|
---|
656 | char *p, *q;
|
---|
657 | FILE *pin, *pout, *faclin;
|
---|
658 |
|
---|
659 | malloc_string(command);
|
---|
660 | log_msg(1, "set_EXAT_list(%s, %s, %s)", orig_msklist,
|
---|
661 | original_exat_fname, executable);
|
---|
662 | if (!orig_msklist || !orig_msklist[0]
|
---|
663 | || !does_file_exist(orig_msklist)) {
|
---|
664 | log_msg(1,
|
---|
665 | "No masklist provided. I shall therefore set ALL attributes.");
|
---|
666 | sprintf(command, "gzip -dc %s | %s --restore - 2>> %s",
|
---|
667 | original_exat_fname, executable, MONDO_LOGFILE);
|
---|
668 | log_msg(1, "command = %s", command);
|
---|
669 | retval = system(command);
|
---|
670 | paranoid_free(command);
|
---|
671 | log_msg(1, "Returning w/ retval=%d", retval);
|
---|
672 | return (retval);
|
---|
673 | }
|
---|
674 | if (length_of_file(original_exat_fname) <= 0) {
|
---|
675 | log_msg(1,
|
---|
676 | "original_exat_fname %s is empty or missing, so no need to set EXAT list",
|
---|
677 | original_exat_fname);
|
---|
678 | paranoid_free(command);
|
---|
679 | return (0);
|
---|
680 | }
|
---|
681 | malloc_string(incoming);
|
---|
682 | malloc_string(masklist);
|
---|
683 | malloc_string(current_subset_file);
|
---|
684 | malloc_string(current_master_file);
|
---|
685 | malloc_string(syscall_pin);
|
---|
686 | malloc_string(syscall_pout);
|
---|
687 | sprintf(masklist, "%s/masklist", bkpinfo->tmpdir);
|
---|
688 | sprintf(command, "cp -f %s %s", orig_msklist, masklist);
|
---|
689 | run_program_and_log_output(command, 1);
|
---|
690 | sort_file(masklist);
|
---|
691 | current_subset_file[0] = current_master_file[0] = '\0';
|
---|
692 | sprintf(syscall_pin, "gzip -dc %s", original_exat_fname);
|
---|
693 | sprintf(syscall_pout, "%s --restore - 2>> %s", executable,
|
---|
694 | MONDO_LOGFILE);
|
---|
695 |
|
---|
696 | log_msg(1, "syscall_pin = %s", syscall_pin);
|
---|
697 | log_msg(1, "syscall_pout = %s", syscall_pout);
|
---|
698 | pout = popen(syscall_pout, "w");
|
---|
699 | if (!pout) {
|
---|
700 | iamhere("Unable to openout to syscall_pout");
|
---|
701 | return (1);
|
---|
702 | }
|
---|
703 | pin = popen(syscall_pin, "r");
|
---|
704 | if (!pin) {
|
---|
705 | pclose(pout);
|
---|
706 | iamhere("Unable to openin from syscall");
|
---|
707 | return (1);
|
---|
708 | }
|
---|
709 | faclin = fopen(masklist, "r");
|
---|
710 | if (!faclin) {
|
---|
711 | pclose(pin);
|
---|
712 | pclose(pout);
|
---|
713 | iamhere("Unable to openin masklist");
|
---|
714 | return (1);
|
---|
715 | }
|
---|
716 | // printf("Hi there. Starting the loop\n");
|
---|
717 |
|
---|
718 | fgets(current_subset_file, MAX_STR_LEN, faclin);
|
---|
719 | fgets(incoming, MAX_STR_LEN, pin);
|
---|
720 | while (!feof(pin) && !feof(faclin)) {
|
---|
721 | // printf("incoming = %s", incoming);
|
---|
722 |
|
---|
723 | strcpy(current_master_file, incoming + 8);
|
---|
724 |
|
---|
725 | p = current_subset_file;
|
---|
726 | if (*p == '/') {
|
---|
727 | p++;
|
---|
728 | }
|
---|
729 | i = strlen(p);
|
---|
730 | if (i > 0 && p[i - 1] < 32) {
|
---|
731 | p[i - 1] = '\0';
|
---|
732 | }
|
---|
733 |
|
---|
734 |
|
---|
735 | q = current_master_file;
|
---|
736 | if (*q == '/') {
|
---|
737 | q++;
|
---|
738 | }
|
---|
739 | i = strlen(q);
|
---|
740 | if (i > 0 && q[i - 1] < 32) {
|
---|
741 | q[i - 1] = '\0';
|
---|
742 | }
|
---|
743 |
|
---|
744 | i = strcmp(p, q);
|
---|
745 | log_msg(my_depth, "'%s' v '%s' --> %d\n", p, q, i);
|
---|
746 |
|
---|
747 | // printf("%s v %s --> %d\n", p, q, i);
|
---|
748 |
|
---|
749 | if (i < 0) { // read another subset file in.
|
---|
750 | log_msg(my_depth, "Reading next subset line in\n\n");
|
---|
751 | fgets(current_subset_file, MAX_STR_LEN, faclin);
|
---|
752 | continue;
|
---|
753 | }
|
---|
754 |
|
---|
755 | if (!i) {
|
---|
756 | fputs(incoming, pout);
|
---|
757 | }
|
---|
758 | fgets(incoming, MAX_STR_LEN, pin);
|
---|
759 | if (!i) {
|
---|
760 | log_msg(my_depth, "Copying master %s", q);
|
---|
761 | }
|
---|
762 | // if (!i) { printf("Match --- %s\n", q); }
|
---|
763 |
|
---|
764 | while (!feof(pin) && strncmp(incoming, "# file: ", 8)) {
|
---|
765 | if (!i) {
|
---|
766 |
|
---|
767 | // printf("%s", incoming);
|
---|
768 |
|
---|
769 | fputs(incoming, pout);
|
---|
770 | }
|
---|
771 | fgets(incoming, MAX_STR_LEN, pin);
|
---|
772 | }
|
---|
773 | if (!i) {
|
---|
774 | fgets(current_subset_file, MAX_STR_LEN, faclin);
|
---|
775 | }
|
---|
776 | }
|
---|
777 | while (!feof(pin)) {
|
---|
778 | fgets(incoming, MAX_STR_LEN, pin);
|
---|
779 | }
|
---|
780 | fclose(faclin);
|
---|
781 | pclose(pin);
|
---|
782 | pclose(pout);
|
---|
783 |
|
---|
784 | // printf("OK, loop is done\n");
|
---|
785 |
|
---|
786 | unlink(masklist);
|
---|
787 | paranoid_free(current_subset_file);
|
---|
788 | paranoid_free(current_master_file);
|
---|
789 | paranoid_free(syscall_pout);
|
---|
790 | paranoid_free(syscall_pin);
|
---|
791 | paranoid_free(masklist);
|
---|
792 | paranoid_free(incoming);
|
---|
793 | paranoid_free(command);
|
---|
794 | return (retval);
|
---|
795 | }
|
---|
796 |
|
---|
797 |
|
---|
798 | int set_fattr_list(char *masklist, char *fattr_fname)
|
---|
799 | {
|
---|
800 | if (find_home_of_exe("setfattr")) {
|
---|
801 | return (set_EXAT_list(masklist, fattr_fname, "setfattr"));
|
---|
802 | } else {
|
---|
803 | log_msg(1, "ERROR: set_EXAT_list: setfattr doesn't exist");
|
---|
804 | return(0);
|
---|
805 | }
|
---|
806 | }
|
---|
807 |
|
---|
808 |
|
---|
809 |
|
---|
810 | int set_acl_list(char *masklist, char *acl_fname)
|
---|
811 | {
|
---|
812 | if (find_home_of_exe("setfacl")) {
|
---|
813 | return (set_EXAT_list(masklist, acl_fname, "setfacl"));
|
---|
814 | } else {
|
---|
815 | log_msg(1, "ERROR: set_EXAT_list: setfacl doesn't exist");
|
---|
816 | return(0);
|
---|
817 | }
|
---|
818 | }
|
---|
819 |
|
---|
820 |
|
---|
821 | /**
|
---|
822 | * Get the number of the last fileset in the backup.
|
---|
823 | * @param bkpinfo The backup information structure. Only the @c bkpinfo->tmpdir field is used.
|
---|
824 | * @return The last filelist number.
|
---|
825 | * @note This function should only be called at restore-time.
|
---|
826 | */
|
---|
827 | int get_last_filelist_number()
|
---|
828 | {
|
---|
829 | /*@ buffers ***************************************************** */
|
---|
830 | char val_sz[MAX_STR_LEN];
|
---|
831 | char cfg_fname[MAX_STR_LEN];
|
---|
832 | /* char tmp[MAX_STR_LEN]; remove stan benoit apr 2002 */
|
---|
833 |
|
---|
834 | /*@ long ******************************************************** */
|
---|
835 | int val_i;
|
---|
836 |
|
---|
837 | /*@ end vars **************************************************** */
|
---|
838 |
|
---|
839 | assert(bkpinfo != NULL);
|
---|
840 |
|
---|
841 | strcpy(val_sz,"");
|
---|
842 | sprintf(cfg_fname, "%s/mondo-restore.cfg", bkpinfo->tmpdir);
|
---|
843 | read_cfg_var(cfg_fname, "last-filelist-number", val_sz);
|
---|
844 | val_i = atoi(val_sz);
|
---|
845 | if (val_i <= 0) {
|
---|
846 | val_i = 500;
|
---|
847 | }
|
---|
848 | return (val_i);
|
---|
849 | }
|
---|
850 |
|
---|
851 |
|
---|
852 | /**
|
---|
853 | * Add a string at @p startnode.
|
---|
854 | * @param startnode The node to start at when searching for where to add the string.
|
---|
855 | * @param string_to_add The string to add.
|
---|
856 | * @return 0 for success, 1 for failure.
|
---|
857 | * @bug I don't understand this function. Would someone care to explain it?
|
---|
858 | */
|
---|
859 | int add_string_at_node(struct s_node *startnode, char *string_to_add)
|
---|
860 | {
|
---|
861 |
|
---|
862 |
|
---|
863 | /*@ int ******************************************************** */
|
---|
864 | int noof_chars;
|
---|
865 | int i;
|
---|
866 | int res;
|
---|
867 |
|
---|
868 | /*@ sturctures ************************************************* */
|
---|
869 | struct s_node *node, *newnode;
|
---|
870 |
|
---|
871 | /*@ char ****************************************************** */
|
---|
872 | char char_to_add;
|
---|
873 |
|
---|
874 | /*@ bools ****************************************************** */
|
---|
875 |
|
---|
876 | const bool sosodef = FALSE;
|
---|
877 |
|
---|
878 | static int depth = 0;
|
---|
879 | static char original_string[MAX_STR_LEN];
|
---|
880 |
|
---|
881 | assert(startnode != NULL);
|
---|
882 | assert(string_to_add != NULL);
|
---|
883 |
|
---|
884 | if (!depth) {
|
---|
885 | strcpy(original_string, string_to_add);
|
---|
886 | }
|
---|
887 |
|
---|
888 | noof_chars = strlen(string_to_add) + 1; /* we include the '\0' */
|
---|
889 |
|
---|
890 | /* walk across tree if necessary */
|
---|
891 | node = startnode;
|
---|
892 | char_to_add = string_to_add[0];
|
---|
893 | if (node->right != NULL && node->ch < char_to_add) {
|
---|
894 | log_msg(7, "depth=%d --- going RIGHT ... %c-->%c", depth,
|
---|
895 | char_to_add, node->ch, (node->right)->ch);
|
---|
896 | return (add_string_at_node(node->right, string_to_add));
|
---|
897 | }
|
---|
898 |
|
---|
899 | /* walk down tree if appropriate */
|
---|
900 | if (node->down != NULL && node->ch == char_to_add) {
|
---|
901 | log_msg(7, "depth=%d char=%c --- going DOWN", depth, char_to_add);
|
---|
902 | depth++;
|
---|
903 | res = add_string_at_node(node->down, string_to_add + 1);
|
---|
904 | depth--;
|
---|
905 | return (res);
|
---|
906 | }
|
---|
907 |
|
---|
908 | if (char_to_add == '\0' && node->ch == '\0') {
|
---|
909 | log_msg(6, "%s already in tree", original_string);
|
---|
910 | return (1);
|
---|
911 | }
|
---|
912 |
|
---|
913 | /* add here */
|
---|
914 | if (!(newnode = (struct s_node *) malloc(sizeof(struct s_node)))) {
|
---|
915 | log_to_screen("failed to malloc");
|
---|
916 | depth--;
|
---|
917 | return (1);
|
---|
918 | }
|
---|
919 | if (char_to_add < node->ch) // add to the left of node
|
---|
920 | {
|
---|
921 | log_msg(7, "depth=%d char=%c --- adding (left)", depth,
|
---|
922 | char_to_add);
|
---|
923 | memcpy((void *) newnode, (void *) node, sizeof(struct s_node));
|
---|
924 | node->right = newnode;
|
---|
925 | } else if (char_to_add > node->ch) // add to the right of node
|
---|
926 | {
|
---|
927 | log_msg(7, "depth=%d char=%c --- adding (right)", depth,
|
---|
928 | char_to_add);
|
---|
929 | newnode->right = node->right; // newnode is to the RIGHT of node
|
---|
930 | node->right = newnode;
|
---|
931 | node = newnode;
|
---|
932 | }
|
---|
933 | // from now on, we're working on 'node'
|
---|
934 | node->down = NULL;
|
---|
935 | node->ch = char_to_add;
|
---|
936 | node->expanded = node->selected = FALSE;
|
---|
937 | if (char_to_add == '\0') {
|
---|
938 | log_msg(6, "Added %s OK", original_string);
|
---|
939 | return (0);
|
---|
940 | }
|
---|
941 | // add the rest
|
---|
942 | log_msg(6, "Adding remaining chars ('%s')", string_to_add + 1);
|
---|
943 | for (i = 1; i < noof_chars; i++) {
|
---|
944 | if (!
|
---|
945 | (node->down =
|
---|
946 | (struct s_node *) malloc(sizeof(struct s_node)))) {
|
---|
947 | log_to_screen("%s - failed to malloc", string_to_add);
|
---|
948 | return (1);
|
---|
949 | }
|
---|
950 | node = node->down;
|
---|
951 | char_to_add = string_to_add[i];
|
---|
952 | log_msg(6, "Adding '%c'", char_to_add);
|
---|
953 | node->ch = char_to_add;
|
---|
954 | node->right = node->down = NULL;
|
---|
955 | node->expanded = node->selected = FALSE;
|
---|
956 | if (!node->ch) {
|
---|
957 | node->selected = sosodef;
|
---|
958 | }
|
---|
959 | }
|
---|
960 | log_msg(6, "Finally - added %s OK", original_string);
|
---|
961 | return (0);
|
---|
962 | }
|
---|
963 |
|
---|
964 |
|
---|
965 |
|
---|
966 |
|
---|
967 | /**
|
---|
968 | * Load a filelist into a <tt>struct s_node</tt>.
|
---|
969 | * When you are done with the filelist, call free_filelist().
|
---|
970 | * @param filelist_fname The file to load the filelist from.
|
---|
971 | * @return A filelist tree structure.
|
---|
972 | */
|
---|
973 | struct s_node *load_filelist(char *filelist_fname)
|
---|
974 | {
|
---|
975 |
|
---|
976 | /*@ structures ************************************************* */
|
---|
977 | struct s_node *filelist;
|
---|
978 |
|
---|
979 | /*@ pointers *************************************************** */
|
---|
980 | FILE *pin;
|
---|
981 |
|
---|
982 | /*@ buffers **************************************************** */
|
---|
983 | char command_to_open_fname[MAX_STR_LEN];
|
---|
984 | char fname[MAX_STR_LEN];
|
---|
985 | char tmp[MAX_STR_LEN];
|
---|
986 | int pos_in_fname;
|
---|
987 | /*@ int ******************************************************** */
|
---|
988 | int percentage;
|
---|
989 |
|
---|
990 | /*@ long ******************************************************* */
|
---|
991 | long lines_in_filelist;
|
---|
992 | long lino = 0;
|
---|
993 | /*@ end vars *************************************************** */
|
---|
994 |
|
---|
995 | assert_string_is_neither_NULL_nor_zerolength(filelist_fname);
|
---|
996 |
|
---|
997 | if (!does_file_exist(filelist_fname)) {
|
---|
998 | fatal_error("filelist does not exist -- cannot load it");
|
---|
999 | }
|
---|
1000 | log_to_screen("Loading filelist");
|
---|
1001 | sprintf(command_to_open_fname, "gzip -dc %s", filelist_fname);
|
---|
1002 | sprintf(tmp, "zcat %s | wc -l", filelist_fname);
|
---|
1003 | log_msg(6, "tmp = %s", tmp);
|
---|
1004 | lines_in_filelist =
|
---|
1005 | atol(call_program_and_get_last_line_of_output(tmp));
|
---|
1006 | if (lines_in_filelist < 3) {
|
---|
1007 | log_to_screen("Warning - surprisingly short filelist.");
|
---|
1008 | }
|
---|
1009 | g_original_noof_lines_in_filelist = lines_in_filelist;
|
---|
1010 | if (!(filelist = (struct s_node *) malloc(sizeof(struct s_node)))) {
|
---|
1011 | return (NULL);
|
---|
1012 | }
|
---|
1013 | filelist->ch = '/';
|
---|
1014 | filelist->right = NULL;
|
---|
1015 | filelist->down = malloc(sizeof(struct s_node));
|
---|
1016 | filelist->expanded = filelist->selected = FALSE;
|
---|
1017 | (filelist->down)->ch = '\0';
|
---|
1018 | (filelist->down)->right = (filelist->down)->down = FALSE;
|
---|
1019 | (filelist->down)->expanded = (filelist->down)->selected = FALSE;
|
---|
1020 | if (!(pin = popen(command_to_open_fname, "r"))) {
|
---|
1021 | log_OS_error("Unable to openin filelist_fname");
|
---|
1022 | return (NULL);
|
---|
1023 | }
|
---|
1024 | open_evalcall_form("Loading filelist from disk");
|
---|
1025 | for (fgets(fname, MAX_STR_LEN, pin); !feof(pin);
|
---|
1026 | fgets(fname, MAX_STR_LEN, pin)) {
|
---|
1027 | if ((fname[strlen(fname) - 1] == 13
|
---|
1028 | || fname[strlen(fname) - 1] == 10) && strlen(fname) > 0) {
|
---|
1029 | fname[strlen(fname) - 1] = '\0';
|
---|
1030 | }
|
---|
1031 | // strip_spaces (fname);
|
---|
1032 | if (!strlen(fname)) {
|
---|
1033 | continue;
|
---|
1034 | }
|
---|
1035 | for (pos_in_fname = 0; fname[pos_in_fname] != '\0'; pos_in_fname++) {
|
---|
1036 | if (fname[pos_in_fname] != '/') {
|
---|
1037 | continue;
|
---|
1038 | }
|
---|
1039 | strcpy(tmp, fname);
|
---|
1040 | tmp[pos_in_fname] = '\0';
|
---|
1041 | if (strlen(tmp)) {
|
---|
1042 | add_string_at_node(filelist, tmp);
|
---|
1043 | }
|
---|
1044 | }
|
---|
1045 | add_string_at_node(filelist, fname);
|
---|
1046 | if (!(++lino % 1111)) {
|
---|
1047 | percentage = (int) (lino * 100 / lines_in_filelist);
|
---|
1048 | update_evalcall_form(percentage);
|
---|
1049 | }
|
---|
1050 | }
|
---|
1051 | paranoid_pclose(pin);
|
---|
1052 | close_evalcall_form();
|
---|
1053 | log_it("Finished loading filelist");
|
---|
1054 | return (filelist);
|
---|
1055 | }
|
---|
1056 |
|
---|
1057 |
|
---|
1058 | /**
|
---|
1059 | * Log a list of files in @p node.
|
---|
1060 | * @param node The toplevel node to use.
|
---|
1061 | */
|
---|
1062 | void show_filelist(struct s_node *node)
|
---|
1063 | {
|
---|
1064 | static int depth = 0;
|
---|
1065 | static char current_string[200];
|
---|
1066 |
|
---|
1067 | if (depth == 0) {
|
---|
1068 | log_msg(0, "----------------show filelist--------------");
|
---|
1069 | }
|
---|
1070 | current_string[depth] = node->ch;
|
---|
1071 |
|
---|
1072 | log_msg(3, "depth=%d", depth);
|
---|
1073 | if (node->down) {
|
---|
1074 | log_msg(3, "moving down");
|
---|
1075 | depth++;
|
---|
1076 | show_filelist(node->down);
|
---|
1077 | depth--;
|
---|
1078 | }
|
---|
1079 |
|
---|
1080 | if (!node->ch) {
|
---|
1081 | log_msg(0, "%s\n", current_string);
|
---|
1082 | }
|
---|
1083 |
|
---|
1084 | if (node->right) {
|
---|
1085 | log_msg(3, "moving right");
|
---|
1086 | show_filelist(node->right);
|
---|
1087 | }
|
---|
1088 | if (depth == 0) {
|
---|
1089 | log_msg(0, "----------------show filelist--------------");
|
---|
1090 | }
|
---|
1091 | return;
|
---|
1092 | }
|
---|
1093 |
|
---|
1094 |
|
---|
1095 |
|
---|
1096 |
|
---|
1097 | /**
|
---|
1098 | * Reset the filelist to the state it was when it was loaded. This does not
|
---|
1099 | * touch the file on disk.
|
---|
1100 | * @param filelist The filelist tree structure.
|
---|
1101 | */
|
---|
1102 | void reload_filelist(struct s_node *filelist)
|
---|
1103 | {
|
---|
1104 | assert(filelist != NULL);
|
---|
1105 | toggle_node_selection(filelist, FALSE);
|
---|
1106 | toggle_path_expandability(filelist, "/", FALSE);
|
---|
1107 | toggle_all_root_dirs_on(filelist);
|
---|
1108 | }
|
---|
1109 |
|
---|
1110 |
|
---|
1111 |
|
---|
1112 | /**
|
---|
1113 | * Save a filelist tree structure to disk.
|
---|
1114 | * @param filelist The filelist tree structure to save.
|
---|
1115 | * @param outfname Where to save it.
|
---|
1116 | */
|
---|
1117 | void save_filelist(struct s_node *filelist, char *outfname)
|
---|
1118 | {
|
---|
1119 | /*@ int ********************************************************* */
|
---|
1120 | static int percentage;
|
---|
1121 | static int depth = 0;
|
---|
1122 |
|
---|
1123 | /*@ buffers ***************************************************** */
|
---|
1124 | static char str[MAX_STR_LEN];
|
---|
1125 |
|
---|
1126 | /*@ structures ************************************************** */
|
---|
1127 | struct s_node *node;
|
---|
1128 |
|
---|
1129 | /*@ pointers **************************************************** */
|
---|
1130 | static FILE *fout = NULL;
|
---|
1131 |
|
---|
1132 | /*@ long ******************************************************** */
|
---|
1133 | static long lines_in_filelist = 0;
|
---|
1134 | static long lino = 0;
|
---|
1135 |
|
---|
1136 | /*@ end vars *************************************************** */
|
---|
1137 |
|
---|
1138 | assert(filelist != NULL);
|
---|
1139 | assert(outfname != NULL); // will be zerolength if save_filelist() is called by itself
|
---|
1140 | if (depth == 0) {
|
---|
1141 | log_to_screen("Saving filelist");
|
---|
1142 | if (!(fout = fopen(outfname, "w"))) {
|
---|
1143 | fatal_error("Cannot openout/save filelist");
|
---|
1144 | }
|
---|
1145 | lines_in_filelist = g_original_noof_lines_in_filelist; /* set by load_filelist() */
|
---|
1146 | open_evalcall_form("Saving selection to disk");
|
---|
1147 | }
|
---|
1148 | for (node = filelist; node != NULL; node = node->right) {
|
---|
1149 | str[depth] = node->ch;
|
---|
1150 | log_msg(5, "depth=%d ch=%c", depth, node->ch);
|
---|
1151 | if (!node->ch) {
|
---|
1152 | // if (node->selected)
|
---|
1153 | // {
|
---|
1154 | fprintf(fout, "%s\n", str);
|
---|
1155 | // }
|
---|
1156 | if (!(++lino % 1111)) {
|
---|
1157 | percentage = (int) (lino * 100 / lines_in_filelist);
|
---|
1158 | update_evalcall_form(percentage);
|
---|
1159 | }
|
---|
1160 | }
|
---|
1161 | if (node->down) {
|
---|
1162 | depth++;
|
---|
1163 | save_filelist(node->down, "");
|
---|
1164 | depth--;
|
---|
1165 | }
|
---|
1166 | }
|
---|
1167 | if (depth == 0) {
|
---|
1168 | paranoid_fclose(fout);
|
---|
1169 | close_evalcall_form();
|
---|
1170 | log_it("Finished saving filelist");
|
---|
1171 | }
|
---|
1172 | }
|
---|
1173 |
|
---|
1174 |
|
---|
1175 |
|
---|
1176 | /**
|
---|
1177 | * Toggle all root dirs on.
|
---|
1178 | * @param filelist The filelist tree structure to operate on.
|
---|
1179 | * @bug I don't understand this function. Would someone care to explain it?
|
---|
1180 | */
|
---|
1181 | void toggle_all_root_dirs_on(struct s_node *filelist)
|
---|
1182 | {
|
---|
1183 | /*@ structures ************************************************** */
|
---|
1184 | struct s_node *node;
|
---|
1185 |
|
---|
1186 | /*@ int ********************************************************* */
|
---|
1187 | static int depth = 0;
|
---|
1188 | static int root_dirs_expanded;
|
---|
1189 |
|
---|
1190 | /*@ buffers ***************************************************** */
|
---|
1191 | static char filename[MAX_STR_LEN];
|
---|
1192 |
|
---|
1193 | /*@ end vars *************************************************** */
|
---|
1194 |
|
---|
1195 | assert(filelist != NULL);
|
---|
1196 | if (depth == 0) {
|
---|
1197 | log_it("Toggling all root dirs ON");
|
---|
1198 | root_dirs_expanded = 0;
|
---|
1199 | }
|
---|
1200 | for (node = filelist; node != NULL; node = node->right) {
|
---|
1201 | filename[depth] = node->ch;
|
---|
1202 | if (node->ch == '\0' && strlen(filename) > 1
|
---|
1203 | && (!strchr(filename + 1, '/'))) {
|
---|
1204 | node->selected = FALSE;
|
---|
1205 | node->expanded = TRUE;
|
---|
1206 | // log_it (filename);
|
---|
1207 | root_dirs_expanded++;
|
---|
1208 | }
|
---|
1209 | if (node->down) {
|
---|
1210 | depth++;
|
---|
1211 | toggle_all_root_dirs_on(node->down);
|
---|
1212 | depth--;
|
---|
1213 | }
|
---|
1214 | }
|
---|
1215 | if (depth == 0) {
|
---|
1216 | log_it("Finished toggling all root dirs ON");
|
---|
1217 | }
|
---|
1218 | }
|
---|
1219 |
|
---|
1220 |
|
---|
1221 | /**
|
---|
1222 | * Toggle the expandability of a path.
|
---|
1223 | * @param filelist The filelist tree to operate on.
|
---|
1224 | * @param pathname The path to toggle expandability of.
|
---|
1225 | * @param on_or_off Whether to toggle it on or off.
|
---|
1226 | * @bug I don't understand this function. Would someone care to explain it?
|
---|
1227 | */
|
---|
1228 | void
|
---|
1229 | toggle_path_expandability(struct s_node *filelist, char *pathname,
|
---|
1230 | bool on_or_off)
|
---|
1231 | {
|
---|
1232 |
|
---|
1233 | /*@ int ******************************************************** */
|
---|
1234 | static int depth = 0;
|
---|
1235 | static int total_expanded;
|
---|
1236 | static int root_depth;
|
---|
1237 | int j;
|
---|
1238 | /*@ structures ************************************************* */
|
---|
1239 | struct s_node *node;
|
---|
1240 |
|
---|
1241 | /*@ buffers **************************************************** */
|
---|
1242 | static char current_filename[MAX_STR_LEN];
|
---|
1243 |
|
---|
1244 | /* char tmp[MAX_STR_LEN+2]; */
|
---|
1245 |
|
---|
1246 | /*@ end vars *************************************************** */
|
---|
1247 |
|
---|
1248 | assert(filelist != NULL);
|
---|
1249 | assert_string_is_neither_NULL_nor_zerolength(pathname);
|
---|
1250 | if (depth == 0) {
|
---|
1251 | total_expanded = 0;
|
---|
1252 | // log_it ("Toggling path's expandability");
|
---|
1253 | for (root_depth = (int) strlen(pathname);
|
---|
1254 | root_depth > 0 && pathname[root_depth - 1] != '/';
|
---|
1255 | root_depth--);
|
---|
1256 | if (root_depth < 2) {
|
---|
1257 | root_depth = (int) strlen(pathname);
|
---|
1258 | }
|
---|
1259 | }
|
---|
1260 | for (node = filelist; node != NULL; node = node->right) {
|
---|
1261 | current_filename[depth] = node->ch;
|
---|
1262 | if (node->down) {
|
---|
1263 | depth++;
|
---|
1264 | toggle_path_expandability(node->down, pathname, on_or_off);
|
---|
1265 | depth--;
|
---|
1266 | }
|
---|
1267 | if (node->ch == '\0') {
|
---|
1268 | if (!strncmp(pathname, current_filename, strlen(pathname))) {
|
---|
1269 | for (j = root_depth;
|
---|
1270 | current_filename[j] != '/'
|
---|
1271 | && current_filename[j] != '\0'; j++);
|
---|
1272 | if (current_filename[j] != '\0') {
|
---|
1273 | for (j++;
|
---|
1274 | current_filename[j] != '/'
|
---|
1275 | && current_filename[j] != '\0'; j++);
|
---|
1276 | }
|
---|
1277 | if (current_filename[j] == '\0') {
|
---|
1278 | node->expanded =
|
---|
1279 | (!strcmp(pathname, current_filename) ? TRUE :
|
---|
1280 | on_or_off);
|
---|
1281 | }
|
---|
1282 | }
|
---|
1283 | }
|
---|
1284 | if (node->expanded) {
|
---|
1285 | if (total_expanded < ARBITRARY_MAXIMUM - 32
|
---|
1286 | || !strrchr(current_filename + strlen(pathname), '/')) {
|
---|
1287 | total_expanded++;
|
---|
1288 | } else {
|
---|
1289 | node->expanded = FALSE;
|
---|
1290 | }
|
---|
1291 | }
|
---|
1292 | }
|
---|
1293 | if (depth == 0) {
|
---|
1294 | // log_it ("Finished toggling expandability");
|
---|
1295 | }
|
---|
1296 | }
|
---|
1297 |
|
---|
1298 | /**
|
---|
1299 | * Toggle whether a path is selected.
|
---|
1300 | * @param filelist The filelist tree to operate on.
|
---|
1301 | * @param pathname The path to toggle selection of.
|
---|
1302 | * @param on_or_off Whether to toggle it on or off.
|
---|
1303 | * @bug I don't understand this function. Would someone care to explain it?
|
---|
1304 | */
|
---|
1305 | void
|
---|
1306 | toggle_path_selection(struct s_node *filelist, char *pathname,
|
---|
1307 | bool on_or_off)
|
---|
1308 | {
|
---|
1309 | /*@ int ********************************************************* */
|
---|
1310 | static int depth = 0;
|
---|
1311 | int j;
|
---|
1312 |
|
---|
1313 | /*@ structures ************************************************** */
|
---|
1314 | struct s_node *node;
|
---|
1315 |
|
---|
1316 | /*@ buffers ***************************************************** */
|
---|
1317 | static char current_filename[MAX_STR_LEN];
|
---|
1318 | char tmp[MAX_STR_LEN + 2];
|
---|
1319 |
|
---|
1320 | /*@ end vars *************************************************** */
|
---|
1321 | assert(filelist != NULL);
|
---|
1322 | assert_string_is_neither_NULL_nor_zerolength(pathname);
|
---|
1323 | if (depth == 0) {
|
---|
1324 | log_it("Toggling path's selection");
|
---|
1325 | }
|
---|
1326 | for (node = filelist; node != NULL; node = node->right) {
|
---|
1327 | current_filename[depth] = node->ch;
|
---|
1328 | if (node->down) {
|
---|
1329 | depth++;
|
---|
1330 | toggle_path_selection(node->down, pathname, on_or_off);
|
---|
1331 | depth--;
|
---|
1332 | }
|
---|
1333 | if (node->ch == '\0') {
|
---|
1334 | if (!strncmp(pathname, current_filename, strlen(pathname))) {
|
---|
1335 | for (j = 0;
|
---|
1336 | pathname[j] != '\0'
|
---|
1337 | && pathname[j] == current_filename[j]; j++);
|
---|
1338 | if (current_filename[j] == '/'
|
---|
1339 | || current_filename[j] == '\0') {
|
---|
1340 | node->selected = on_or_off;
|
---|
1341 | sprintf(tmp, "%s is now %s\n", current_filename,
|
---|
1342 | (on_or_off ? "ON" : "OFF"));
|
---|
1343 | }
|
---|
1344 | }
|
---|
1345 | }
|
---|
1346 | }
|
---|
1347 | if (depth == 0) {
|
---|
1348 | log_it("Finished toggling selection");
|
---|
1349 | }
|
---|
1350 | }
|
---|
1351 |
|
---|
1352 |
|
---|
1353 | /**
|
---|
1354 | * Toggle node selection of a filelist tree.
|
---|
1355 | * @param filelist The filelist tree to operate on.
|
---|
1356 | * @param on_or_off Whether to toggle selection on or off.
|
---|
1357 | * @bug I don't understand this function. Would someone care to explain it?
|
---|
1358 | */
|
---|
1359 | void toggle_node_selection(struct s_node *filelist, bool on_or_off)
|
---|
1360 | {
|
---|
1361 | /*@ structure ************************************************** */
|
---|
1362 | struct s_node *node;
|
---|
1363 |
|
---|
1364 | /*@ end vars *************************************************** */
|
---|
1365 | assert(filelist != NULL);
|
---|
1366 | for (node = filelist; node != NULL; node = node->right) {
|
---|
1367 | if (node->ch == '/') {
|
---|
1368 | continue;
|
---|
1369 | } /* don't go deep */
|
---|
1370 | if (node->ch == '\0') {
|
---|
1371 | node->selected = on_or_off;
|
---|
1372 | }
|
---|
1373 | if (node->down) {
|
---|
1374 | toggle_node_selection(node->down, on_or_off);
|
---|
1375 | }
|
---|
1376 | }
|
---|
1377 | }
|
---|
1378 |
|
---|
1379 |
|
---|
1380 |
|
---|
1381 |
|
---|
1382 |
|
---|
1383 |
|
---|
1384 |
|
---|
1385 | /**
|
---|
1386 | * The pathname to the skeleton filelist, used to give better progress reporting for mondo_makefilelist().
|
---|
1387 | */
|
---|
1388 | char *g_skeleton_filelist = NULL;
|
---|
1389 |
|
---|
1390 | /**
|
---|
1391 | * Number of entries in the skeleton filelist.
|
---|
1392 | */
|
---|
1393 | long g_skeleton_entries = 0;
|
---|
1394 |
|
---|
1395 | /**
|
---|
1396 | * Wrapper around mondo_makefilelist().
|
---|
1397 | * @param bkpinfo The backup information structure. Fields used:
|
---|
1398 | * - @c bkpinfo->differential
|
---|
1399 | * - @c bkpinfo->exclude_paths
|
---|
1400 | * - @c bkpinfo->include_paths
|
---|
1401 | * - @c bkpinfo->make_filelist
|
---|
1402 | * - @c bkpinfo->scratchdir
|
---|
1403 | * - @c bkpinfo->tmpdir
|
---|
1404 | * @return 0 for success, nonzero for failure.
|
---|
1405 | * @see mondo_makefilelist
|
---|
1406 | */
|
---|
1407 | int prepare_filelist()
|
---|
1408 | {
|
---|
1409 |
|
---|
1410 | /*@ int **************************************************** */
|
---|
1411 | int res = 0;
|
---|
1412 |
|
---|
1413 | assert(bkpinfo != NULL);
|
---|
1414 | log_it("tmpdir=%s; scratchdir=%s", bkpinfo->tmpdir,
|
---|
1415 | bkpinfo->scratchdir);
|
---|
1416 | if (bkpinfo->make_filelist) {
|
---|
1417 | mvaddstr_and_log_it(g_currentY, 0,
|
---|
1418 | "Making catalog of files to be backed up");
|
---|
1419 | } else {
|
---|
1420 | mvaddstr_and_log_it(g_currentY, 0,
|
---|
1421 | "Using supplied catalog of files to be backed up");
|
---|
1422 | }
|
---|
1423 |
|
---|
1424 | if (bkpinfo->make_filelist) {
|
---|
1425 | res =
|
---|
1426 | mondo_makefilelist(MONDO_LOGFILE, bkpinfo->tmpdir,
|
---|
1427 | bkpinfo->scratchdir, bkpinfo->include_paths,
|
---|
1428 | bkpinfo->exclude_paths,
|
---|
1429 | bkpinfo->differential, NULL);
|
---|
1430 | } else {
|
---|
1431 | res =
|
---|
1432 | mondo_makefilelist(MONDO_LOGFILE, bkpinfo->tmpdir,
|
---|
1433 | bkpinfo->scratchdir, NULL,
|
---|
1434 | bkpinfo->exclude_paths,
|
---|
1435 | bkpinfo->differential,
|
---|
1436 | bkpinfo->include_paths);
|
---|
1437 | }
|
---|
1438 |
|
---|
1439 | if (res) {
|
---|
1440 | log_OS_error("Call to mondo_makefilelist failed");
|
---|
1441 | mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
|
---|
1442 | } else {
|
---|
1443 | mvaddstr_and_log_it(g_currentY++, 74, "Done.");
|
---|
1444 | }
|
---|
1445 | return (res);
|
---|
1446 | }
|
---|
1447 |
|
---|
1448 |
|
---|
1449 | /**
|
---|
1450 | * Recursively list all files in @p dir newer than @p time_of_last_full_backup to @p fout.
|
---|
1451 | * @param dir The directory to list to @p fout.
|
---|
1452 | * @param sth The directories to skip (exclude).
|
---|
1453 | * @param fout The file to write everything to.
|
---|
1454 | * @param time_of_last_full_backup Only backup files newer than this (0 to disable).
|
---|
1455 | * @return 0, always.
|
---|
1456 | * @bug Return value should be @c void.
|
---|
1457 | */
|
---|
1458 | int open_and_list_dir(char *dir, char *sth, FILE * fout,
|
---|
1459 | time_t time_of_last_full_backup)
|
---|
1460 | {
|
---|
1461 | const char delims[] = " ";
|
---|
1462 |
|
---|
1463 | DIR *dip;
|
---|
1464 | struct dirent *dit;
|
---|
1465 | struct stat statbuf;
|
---|
1466 | char new[MAX_STR_LEN];
|
---|
1467 | char *tmp;
|
---|
1468 | char *sth_B;
|
---|
1469 | static int percentage = 0;
|
---|
1470 | char *ith_B;
|
---|
1471 | char *skip_these;
|
---|
1472 | char *new_with_spaces;
|
---|
1473 | char *strtmp;
|
---|
1474 | char *token;
|
---|
1475 | char *find_excludes;
|
---|
1476 | static char *name_of_evalcall_form;
|
---|
1477 | int i;
|
---|
1478 | int lastpos = 0;
|
---|
1479 | static int depth = 0;
|
---|
1480 | char *p;
|
---|
1481 | static int counter = 0;
|
---|
1482 | static int uberctr = 0;
|
---|
1483 | static char *find_skeleton_marker;
|
---|
1484 | static long skeleton_lino = 0;
|
---|
1485 | static time_t last_time = 0;
|
---|
1486 | time_t this_time;
|
---|
1487 |
|
---|
1488 | malloc_string(tmp);
|
---|
1489 | sth_B = malloc(8*MAX_STR_LEN);
|
---|
1490 | malloc_string(ith_B);
|
---|
1491 | malloc_string(new_with_spaces);
|
---|
1492 | p = strrchr(dir, '/');
|
---|
1493 | if (p) {
|
---|
1494 | if (!strcmp(p, "/.") || !strcmp(p, "/..")) {
|
---|
1495 | return (0);
|
---|
1496 | }
|
---|
1497 | }
|
---|
1498 |
|
---|
1499 | if (!depth) {
|
---|
1500 | malloc_string(name_of_evalcall_form);
|
---|
1501 | malloc_string(find_skeleton_marker);
|
---|
1502 | asprintf(&find_excludes, " ");
|
---|
1503 | while((token = mr_strtok (sth, delims, &lastpos))) {
|
---|
1504 | asprintf(&strtmp,"%s", find_excludes);
|
---|
1505 | paranoid_free(find_excludes);
|
---|
1506 | asprintf(&find_excludes,"%s -path %s -prune -o", strtmp, token);
|
---|
1507 | paranoid_free(strtmp);
|
---|
1508 | paranoid_free(token);
|
---|
1509 | }
|
---|
1510 | #if linux
|
---|
1511 | // 2.6 has /sys as a proc-type thing -- must be excluded
|
---|
1512 | asprintf(&strtmp,
|
---|
1513 | "find %s -maxdepth %d -fstype mvfs -prune -o -path /dev/shm -prune -o %s -type d -print > %s 2> /dev/null",
|
---|
1514 | dir, MAX_SKEL_DEPTH, find_excludes, g_skeleton_filelist);
|
---|
1515 | #else
|
---|
1516 | // On BSD, for example, /sys is the kernel sources -- don't exclude
|
---|
1517 | asprintf(&strtmp,
|
---|
1518 | "find %s -maxdepth %d -fstype mvfs -prune -o -path /proc -prune -o %s -type d -print > %s 2> /dev/null",
|
---|
1519 | dir, MAX_SKEL_DEPTH, find_excludes, g_skeleton_filelist);
|
---|
1520 | #endif
|
---|
1521 | paranoid_free(find_excludes);
|
---|
1522 | log_msg(5, "find command = %s", strtmp);
|
---|
1523 | system(strtmp);
|
---|
1524 | paranoid_free(strtmp);
|
---|
1525 | sprintf(tmp, "wc -l %s | awk '{print $1;}'", g_skeleton_filelist);
|
---|
1526 | g_skeleton_entries =
|
---|
1527 | 1 + atol(call_program_and_get_last_line_of_output(tmp));
|
---|
1528 | sprintf(name_of_evalcall_form, "Making catalog of %s", dir);
|
---|
1529 | open_evalcall_form(name_of_evalcall_form);
|
---|
1530 | find_skeleton_marker[0] = '\0';
|
---|
1531 | skeleton_lino = 1;
|
---|
1532 | log_msg(5, "entries = %ld", g_skeleton_entries);
|
---|
1533 | percentage = 0;
|
---|
1534 | } else if (depth <= MAX_SKEL_DEPTH) // update evalcall form if appropriate
|
---|
1535 | {
|
---|
1536 | sprintf(find_skeleton_marker,
|
---|
1537 | "grep -Fv \"%s\" %s > %s.new 2> /dev/null", dir,
|
---|
1538 | g_skeleton_filelist, g_skeleton_filelist);
|
---|
1539 | // log_msg(0, "fsm = %s", find_skeleton_marker);
|
---|
1540 | if (!system(find_skeleton_marker)) {
|
---|
1541 | percentage = (int) (skeleton_lino * 100 / g_skeleton_entries);
|
---|
1542 | skeleton_lino++;
|
---|
1543 | // log_msg(5, "Found %s", dir);
|
---|
1544 | // log_msg(2, "Incrementing skeleton_lino; now %ld/%ld (%d%%)", skeleton_lino, g_skeleton_entries, percentage);
|
---|
1545 | sprintf(find_skeleton_marker, "mv -f %s.new %s",
|
---|
1546 | g_skeleton_filelist, g_skeleton_filelist);
|
---|
1547 | // log_msg(6, "fsm = %s", find_skeleton_marker);
|
---|
1548 | run_program_and_log_output(find_skeleton_marker, 8);
|
---|
1549 | time(&this_time);
|
---|
1550 | if (this_time != last_time) {
|
---|
1551 | last_time = this_time;
|
---|
1552 | #ifndef _XWIN
|
---|
1553 | if (!g_text_mode) {
|
---|
1554 | sprintf(tmp, "Reading %-68s", dir);
|
---|
1555 | newtDrawRootText(0, g_noof_rows - 3, tmp);
|
---|
1556 | }
|
---|
1557 | #endif
|
---|
1558 | update_evalcall_form(percentage);
|
---|
1559 | }
|
---|
1560 | }
|
---|
1561 | }
|
---|
1562 |
|
---|
1563 | depth++;
|
---|
1564 |
|
---|
1565 | // log_msg(0, "Cataloguing %s", dir);
|
---|
1566 | if (sth[0] == ' ') {
|
---|
1567 | skip_these = sth;
|
---|
1568 | } else {
|
---|
1569 | skip_these = sth_B;
|
---|
1570 | sprintf(skip_these, " %s ", sth);
|
---|
1571 | }
|
---|
1572 | sprintf(new_with_spaces, " %s ", dir);
|
---|
1573 | if ((dip = opendir(dir)) == NULL) {
|
---|
1574 | sprintf(tmp,"opendir %s", dir);
|
---|
1575 | log_OS_error(tmp);
|
---|
1576 | } else if (strstr(skip_these, new_with_spaces)) {
|
---|
1577 | fprintf(fout, "%s\n", dir); // if excluded dir then print dir ONLY
|
---|
1578 | } else {
|
---|
1579 | fprintf(fout, "%s\n", dir);
|
---|
1580 | while ((dit = readdir(dip)) != NULL) {
|
---|
1581 | i++;
|
---|
1582 | strcpy(new, dir);
|
---|
1583 | if (strcmp(dir, "/")) {
|
---|
1584 | strcat(new, "/");
|
---|
1585 | }
|
---|
1586 | strcat(new, dit->d_name);
|
---|
1587 | new_with_spaces[0] = ' ';
|
---|
1588 | strcpy(new_with_spaces + 1, new);
|
---|
1589 | strcat(new_with_spaces, " ");
|
---|
1590 | if (strstr(skip_these, new_with_spaces)) {
|
---|
1591 | fprintf(fout, "%s\n", new);
|
---|
1592 | } else {
|
---|
1593 | if (!lstat(new, &statbuf)) {
|
---|
1594 | if (!S_ISLNK(statbuf.st_mode)
|
---|
1595 | && S_ISDIR(statbuf.st_mode)) {
|
---|
1596 | open_and_list_dir(new, skip_these, fout,
|
---|
1597 | time_of_last_full_backup);
|
---|
1598 | } else {
|
---|
1599 | if (time_of_last_full_backup == 0
|
---|
1600 | || time_of_last_full_backup <
|
---|
1601 | statbuf.st_ctime) {
|
---|
1602 | fprintf(fout, "%s\n", new);
|
---|
1603 | if ((counter++) > 128) {
|
---|
1604 | counter = 0;
|
---|
1605 | uberctr++;
|
---|
1606 | sprintf(tmp, " %c ",
|
---|
1607 | special_dot_char(uberctr));
|
---|
1608 | #ifndef _XWIN
|
---|
1609 | if (!g_text_mode) {
|
---|
1610 | newtDrawRootText(77, g_noof_rows - 3,
|
---|
1611 | tmp);
|
---|
1612 | newtRefresh();
|
---|
1613 | }
|
---|
1614 | #endif
|
---|
1615 | }
|
---|
1616 | }
|
---|
1617 | }
|
---|
1618 | }
|
---|
1619 | }
|
---|
1620 | }
|
---|
1621 | }
|
---|
1622 | if (dip) {
|
---|
1623 | if (closedir(dip) == -1) {
|
---|
1624 | log_OS_error("closedir");
|
---|
1625 | }
|
---|
1626 | }
|
---|
1627 | depth--;
|
---|
1628 | if (!depth) {
|
---|
1629 | close_evalcall_form();
|
---|
1630 | paranoid_free(name_of_evalcall_form);
|
---|
1631 | paranoid_free(find_skeleton_marker);
|
---|
1632 | unlink(g_skeleton_filelist);
|
---|
1633 | log_msg(5, "g_skeleton_entries = %ld", g_skeleton_entries);
|
---|
1634 | }
|
---|
1635 | paranoid_free(tmp);
|
---|
1636 | paranoid_free(sth_B);
|
---|
1637 | paranoid_free(ith_B);
|
---|
1638 | paranoid_free(new_with_spaces);
|
---|
1639 | return (0);
|
---|
1640 | }
|
---|
1641 |
|
---|
1642 |
|
---|
1643 |
|
---|
1644 | /**
|
---|
1645 | * Get the next entry in the space-separated list in @p incoming.
|
---|
1646 | * So if @p incoming was '"one and two" three four', we would
|
---|
1647 | * return "one and two".
|
---|
1648 | * @param incoming The list to get the next entry from.
|
---|
1649 | * @return The first item in the list (respecting double quotes).
|
---|
1650 | * @note The returned string points to static data that will be overwritten with each call.
|
---|
1651 | */
|
---|
1652 | char *next_entry(char *incoming)
|
---|
1653 | {
|
---|
1654 | static char sz_res[MAX_STR_LEN];
|
---|
1655 | char *p;
|
---|
1656 | bool in_quotes = FALSE;
|
---|
1657 |
|
---|
1658 | strcpy(sz_res, incoming);
|
---|
1659 | p = sz_res;
|
---|
1660 | while ((*p != ' ' || in_quotes) && *p != '\0') {
|
---|
1661 | if (*p == '\"') {
|
---|
1662 | in_quotes = !in_quotes;
|
---|
1663 | }
|
---|
1664 | p++;
|
---|
1665 | }
|
---|
1666 | *p = '\0';
|
---|
1667 | return (sz_res);
|
---|
1668 | }
|
---|
1669 |
|
---|
1670 |
|
---|
1671 |
|
---|
1672 | /**
|
---|
1673 | * Create the filelist for the backup. It will be stored in [scratchdir]/archives/filelist.full.
|
---|
1674 | * @param logfile Unused.
|
---|
1675 | * @param tmpdir The tmpdir of the backup.
|
---|
1676 | * @param scratchdir The scratchdir of the backup.
|
---|
1677 | * @param include_paths The paths to back up, or NULL if you're using a user-defined filelist.
|
---|
1678 | * @param excp The paths to NOT back up.
|
---|
1679 | * @param differential The differential level (currently only 0 and 1 are supported).
|
---|
1680 | * @param userdef_filelist The user-defined filelist, or NULL if you're using @p include_paths.
|
---|
1681 | * @return 0, always.
|
---|
1682 | * @bug @p logfile is unused.
|
---|
1683 | * @bug Return value is meaningless.
|
---|
1684 | */
|
---|
1685 | int mondo_makefilelist(char *logfile, char *tmpdir, char *scratchdir,
|
---|
1686 | char *include_paths, char *excp, int differential,
|
---|
1687 | char *userdef_filelist)
|
---|
1688 | {
|
---|
1689 | char sz_datefile_wildcard[] = MONDO_CACHE"/difflevel.%d";
|
---|
1690 | char *p, *q;
|
---|
1691 | char sz_datefile[80];
|
---|
1692 | char *sz_filelist, *exclude_paths, *tmp;
|
---|
1693 | int i;
|
---|
1694 | FILE *fout;
|
---|
1695 | char *command;
|
---|
1696 | time_t time_of_last_full_backup = 0;
|
---|
1697 | struct stat statbuf;
|
---|
1698 | char *tmp1 = NULL;
|
---|
1699 | char *tmp2 = NULL;
|
---|
1700 |
|
---|
1701 | malloc_string(command);
|
---|
1702 | malloc_string(tmp);
|
---|
1703 | malloc_string(sz_filelist);
|
---|
1704 | malloc_string(g_skeleton_filelist);
|
---|
1705 | if (!(exclude_paths = malloc(8*MAX_STR_LEN))) {
|
---|
1706 | fatal_error("Cannot malloc exclude_paths");
|
---|
1707 | }
|
---|
1708 | sprintf(sz_datefile, sz_datefile_wildcard, 0);
|
---|
1709 | if (!include_paths && !userdef_filelist) {
|
---|
1710 | fatal_error
|
---|
1711 | ("Please supply either include_paths or userdef_filelist");
|
---|
1712 | }
|
---|
1713 | // make hole for filelist
|
---|
1714 | sprintf(command, "mkdir -p %s/archives", scratchdir);
|
---|
1715 | paranoid_system(command);
|
---|
1716 | sprintf(sz_filelist, "%s/tmpfs/filelist.full", tmpdir);
|
---|
1717 | make_hole_for_file(sz_filelist);
|
---|
1718 |
|
---|
1719 | if (differential == 0) {
|
---|
1720 | // restore last good datefile if it exists
|
---|
1721 | sprintf(command, "cp -f %s.aborted %s", sz_datefile, sz_datefile);
|
---|
1722 | run_program_and_log_output(command, 3);
|
---|
1723 | // backup last known good datefile just in case :)
|
---|
1724 | if (does_file_exist(sz_datefile)) {
|
---|
1725 | sprintf(command, "mv -f %s %s.aborted", sz_datefile,
|
---|
1726 | sz_datefile);
|
---|
1727 | paranoid_system(command);
|
---|
1728 | }
|
---|
1729 | make_hole_for_file(sz_datefile);
|
---|
1730 | write_one_liner_data_file(sz_datefile,
|
---|
1731 | call_program_and_get_last_line_of_output
|
---|
1732 | ("date +%s"));
|
---|
1733 | } else if (lstat(sz_datefile, &statbuf)) {
|
---|
1734 | log_msg(2,
|
---|
1735 | "Warning - unable to find date of previous backup. Full backup instead.");
|
---|
1736 | differential = 0;
|
---|
1737 | time_of_last_full_backup = 0;
|
---|
1738 | } else {
|
---|
1739 | time_of_last_full_backup = statbuf.st_mtime;
|
---|
1740 | log_msg(2, "Differential backup. Yay.");
|
---|
1741 | }
|
---|
1742 |
|
---|
1743 | // use user-specified filelist (if specified)
|
---|
1744 | if (userdef_filelist) {
|
---|
1745 | log_msg(1,
|
---|
1746 | "Using the user-specified filelist - %s - instead of calculating one",
|
---|
1747 | userdef_filelist);
|
---|
1748 | sprintf(command, "cp -f %s %s", userdef_filelist, sz_filelist);
|
---|
1749 | if (run_program_and_log_output(command, 3)) {
|
---|
1750 | fatal_error("Failed to copy user-specified filelist");
|
---|
1751 | }
|
---|
1752 | } else {
|
---|
1753 | log_msg(2, "include_paths = '%s'", include_paths);
|
---|
1754 | log_msg(1, "Calculating filelist");
|
---|
1755 | asprintf(&tmp2, call_program_and_get_last_line_of_output("mount | grep -Ew 'ntfs|fat|vfat|dos' | awk '{print $3}'"));
|
---|
1756 | if (strlen(tmp2) < 1) {
|
---|
1757 | asprintf(&tmp1," ");
|
---|
1758 | } else {
|
---|
1759 | log_msg(2, "Found windows FS: %s",tmp2);
|
---|
1760 | asprintf(&tmp1, "find %s -name '/win386.swp' -o -name '/hiberfil.sys' -o -name '/pagefile.sys' 2> /dev/null\n",tmp2);
|
---|
1761 | paranoid_free(tmp2);
|
---|
1762 | asprintf(&tmp2, call_program_and_get_last_line_of_output(tmp1));
|
---|
1763 | log_msg(2, "Found windows files: %s",tmp2);
|
---|
1764 | }
|
---|
1765 | paranoid_free(tmp1);
|
---|
1766 |
|
---|
1767 | snprintf(exclude_paths, (size_t)8*MAX_STR_LEN," %s %s %s %s %s . .. \
|
---|
1768 | " MNT_CDROM " " MNT_FLOPPY " /media /tmp \
|
---|
1769 | /proc /sys /var/cache/mondo " MINDI_CACHE, MONDO_CACHE, excp, tmp2, (tmpdir[0] == '/' && tmpdir[1] == '/') ? (tmpdir + 1) : tmpdir, (scratchdir[0] == '/' && scratchdir[1] == '/') ? (scratchdir + 1) : scratchdir);
|
---|
1770 | paranoid_free(tmp2);
|
---|
1771 |
|
---|
1772 | log_msg(2, "Excluding paths = '%s'", exclude_paths);
|
---|
1773 | log_msg(2,
|
---|
1774 | "Generating skeleton filelist so that we can track our progress");
|
---|
1775 | sprintf(g_skeleton_filelist, "%s/tmpfs/skeleton.txt", tmpdir);
|
---|
1776 | make_hole_for_file(g_skeleton_filelist);
|
---|
1777 | log_msg(4, "g_skeleton_entries = %ld", g_skeleton_entries);
|
---|
1778 | log_msg(2, "Opening out filelist to %s", sz_filelist);
|
---|
1779 | if (!(fout = fopen(sz_filelist, "w"))) {
|
---|
1780 | fatal_error("Cannot openout to sz_filelist");
|
---|
1781 | }
|
---|
1782 | i = 0;
|
---|
1783 | if (strlen(include_paths) == 0) {
|
---|
1784 | log_msg(1, "Including only '/' in %s", sz_filelist);
|
---|
1785 | open_and_list_dir("/", exclude_paths, fout,
|
---|
1786 | time_of_last_full_backup);
|
---|
1787 | } else {
|
---|
1788 | p = include_paths;
|
---|
1789 | while (*p) {
|
---|
1790 | q = next_entry(p);
|
---|
1791 | log_msg(1, "Including %s in filelist %s", q, sz_filelist);
|
---|
1792 | open_and_list_dir(q, exclude_paths, fout,
|
---|
1793 | time_of_last_full_backup);
|
---|
1794 | p += strlen(q);
|
---|
1795 | while (*p == ' ') {
|
---|
1796 | p++;
|
---|
1797 | }
|
---|
1798 | }
|
---|
1799 | }
|
---|
1800 | paranoid_fclose(fout);
|
---|
1801 | }
|
---|
1802 | log_msg(2, "Copying new filelist to scratchdir");
|
---|
1803 | sprintf(command, "mkdir -p %s/archives", scratchdir);
|
---|
1804 | paranoid_system(command);
|
---|
1805 | sprintf(command, "cp -f %s %s/archives/", sz_filelist, scratchdir);
|
---|
1806 | paranoid_system(command);
|
---|
1807 | sprintf(command, "mv -f %s %s", sz_filelist, tmpdir);
|
---|
1808 | paranoid_system(command);
|
---|
1809 | log_msg(2, "Freeing variables");
|
---|
1810 | paranoid_free(sz_filelist);
|
---|
1811 | paranoid_free(command);
|
---|
1812 | paranoid_free(exclude_paths);
|
---|
1813 | paranoid_free(tmp);
|
---|
1814 | paranoid_free(g_skeleton_filelist);
|
---|
1815 | log_msg(2, "Exiting");
|
---|
1816 | return (0);
|
---|
1817 | }
|
---|
1818 |
|
---|
1819 |
|
---|
1820 |
|
---|
1821 |
|
---|
1822 | /**
|
---|
1823 | * Locate the string @p string_to_find in the tree rooted at @p startnode.
|
---|
1824 | * @param startnode The node containing the root of the directory tree.
|
---|
1825 | * @param string_to_find The string to look for at @p startnode.
|
---|
1826 | * @return The node containing the last element of @p string_to_find, or NULL if
|
---|
1827 | * it was not found.
|
---|
1828 | */
|
---|
1829 | struct s_node *find_string_at_node(struct s_node *startnode,
|
---|
1830 | char *string_to_find)
|
---|
1831 | {
|
---|
1832 | /*@ int ******************************************************** */
|
---|
1833 | int noof_chars;
|
---|
1834 | static int depth = 0;
|
---|
1835 | static char original_string[MAX_STR_LEN];
|
---|
1836 |
|
---|
1837 | /*@ sturctures ************************************************* */
|
---|
1838 | struct s_node *node;
|
---|
1839 |
|
---|
1840 | /*@ char ****************************************************** */
|
---|
1841 | char char_to_find;
|
---|
1842 |
|
---|
1843 | /*@ bools ****************************************************** */
|
---|
1844 |
|
---|
1845 | if (!depth) {
|
---|
1846 | strcpy(original_string, string_to_find);
|
---|
1847 | }
|
---|
1848 |
|
---|
1849 | assert(startnode != NULL);
|
---|
1850 | assert(string_to_find != NULL);
|
---|
1851 |
|
---|
1852 | noof_chars = strlen(string_to_find) + 1; /* we include the '\0' */
|
---|
1853 |
|
---|
1854 | log_msg(7, "starting --- str=%s", string_to_find);
|
---|
1855 |
|
---|
1856 | /* walk across tree if necessary */
|
---|
1857 | node = startnode;
|
---|
1858 | char_to_find = string_to_find[0];
|
---|
1859 | if (node->right != NULL && node->ch < char_to_find) {
|
---|
1860 | log_msg(7, "depth=%d --- going RIGHT ... %c-->%c", depth,
|
---|
1861 | char_to_find, node->ch, (node->right)->ch);
|
---|
1862 | return (find_string_at_node(node->right, string_to_find));
|
---|
1863 | }
|
---|
1864 |
|
---|
1865 | /* walk down tree if appropriate */
|
---|
1866 | if (node->down != NULL && node->ch == char_to_find) {
|
---|
1867 | log_msg(7, "depth=%d char=%c --- going DOWN", depth, char_to_find);
|
---|
1868 | depth++;
|
---|
1869 | node = find_string_at_node(node->down, string_to_find + 1);
|
---|
1870 | depth--;
|
---|
1871 | return (node);
|
---|
1872 | }
|
---|
1873 |
|
---|
1874 | if (char_to_find == '\0' && node->ch == '\0') {
|
---|
1875 | log_msg(7, "%s is in tree", original_string);
|
---|
1876 | return (node);
|
---|
1877 | } else {
|
---|
1878 | log_msg(7, "%s is NOT in tree", original_string);
|
---|
1879 | return (NULL);
|
---|
1880 | }
|
---|
1881 | }
|
---|
1882 |
|
---|
1883 |
|
---|
1884 |
|
---|
1885 | /**
|
---|
1886 | * Write all entries in @p needles_list_fname which are also in
|
---|
1887 | * @p filelist to @p matches_list_fname.
|
---|
1888 | * @param needles_list_fname A file containing strings to look for, 1 per line.
|
---|
1889 | * @param filelist The node for the root of the directory structure to search in.
|
---|
1890 | * @param matches_list_fname The filename where we should put the matches.
|
---|
1891 | * @return The number of matches found.
|
---|
1892 | */
|
---|
1893 | long save_filelist_entries_in_common(char *needles_list_fname,
|
---|
1894 | struct s_node *filelist,
|
---|
1895 | char *matches_list_fname,
|
---|
1896 | bool use_star)
|
---|
1897 | {
|
---|
1898 | int retval = 0;
|
---|
1899 | struct s_node *found_node;
|
---|
1900 | FILE *fin;
|
---|
1901 | FILE *fout;
|
---|
1902 | char *fname;
|
---|
1903 | char *tmp;
|
---|
1904 | size_t len = 0; // Scrub's patch doesn't work without that
|
---|
1905 |
|
---|
1906 | // log_msg(1, "use_star = %s", (use_star)?"TRUE":"FALSE");
|
---|
1907 | malloc_string(fname);
|
---|
1908 | malloc_string(tmp);
|
---|
1909 | log_msg(5, "starting");
|
---|
1910 | log_msg(5, "needles_list_fname = %s", needles_list_fname);
|
---|
1911 | log_msg(5, "matches_list_fname = %s", matches_list_fname);
|
---|
1912 | if (!(fin = fopen(needles_list_fname, "r"))) {
|
---|
1913 | fatal_error("Cannot openin needles_list_fname");
|
---|
1914 | }
|
---|
1915 | if (!(fout = fopen(matches_list_fname, "w"))) {
|
---|
1916 | fatal_error("Cannot openout matches_list_fname");
|
---|
1917 | }
|
---|
1918 | while (!feof(fin)) {
|
---|
1919 | // fscanf(fin, "%s\n", fname);
|
---|
1920 | len = MAX_STR_LEN - 1;
|
---|
1921 | getline(&fname, &len, fin); // patch by Scrub
|
---|
1922 | if (!use_star) {
|
---|
1923 | if (fname[0] == '/') {
|
---|
1924 | strcpy(tmp, fname);
|
---|
1925 | } else {
|
---|
1926 | tmp[0] = '/';
|
---|
1927 | strcpy(tmp + 1, fname);
|
---|
1928 | }
|
---|
1929 | strcpy(fname, tmp);
|
---|
1930 | }
|
---|
1931 | while (strlen(fname) > 0 && fname[strlen(fname) - 1] < 32) {
|
---|
1932 | fname[strlen(fname) - 1] = '\0';
|
---|
1933 | }
|
---|
1934 |
|
---|
1935 | /*
|
---|
1936 | if (strlen(fname)>3 && fname[strlen(fname)-1]=='/') { fname[strlen(fname)-1] = '\0'; }
|
---|
1937 | if (strlen(fname)==0) { continue; }
|
---|
1938 | sprintf(temporary_string, "echo \"Looking for '%s'\" >> /tmp/looking.txt", fname);
|
---|
1939 | system(temporary_string);
|
---|
1940 | */
|
---|
1941 |
|
---|
1942 | log_msg(5, "Looking for '%s'", fname);
|
---|
1943 | found_node = find_string_at_node(filelist, fname);
|
---|
1944 | if (found_node) {
|
---|
1945 | if (found_node->selected) {
|
---|
1946 | // if (use_star)
|
---|
1947 | if (fname[0] == '/') {
|
---|
1948 | strcpy(tmp, fname + 1);
|
---|
1949 | strcpy(fname, tmp);
|
---|
1950 | }
|
---|
1951 | log_msg(5, "Found '%s'", fname);
|
---|
1952 | turn_wildcard_chars_into_literal_chars(tmp, fname);
|
---|
1953 | fprintf(fout, "%s\n", tmp);
|
---|
1954 | retval++;
|
---|
1955 | }
|
---|
1956 | }
|
---|
1957 | }
|
---|
1958 | paranoid_fclose(fout);
|
---|
1959 | paranoid_fclose(fin);
|
---|
1960 | paranoid_free(fname);
|
---|
1961 | paranoid_free(tmp);
|
---|
1962 | return (retval);
|
---|
1963 | }
|
---|
1964 |
|
---|
1965 |
|
---|
1966 |
|
---|
1967 |
|
---|
1968 |
|
---|
1969 |
|
---|
1970 | /**
|
---|
1971 | * Add all files listed in @p list_of_files_fname to the directory structure rooted at
|
---|
1972 | * @p filelist.
|
---|
1973 | * @param filelist The top node of the directory structure to add the files to.
|
---|
1974 | * @param list_of_files_fname The file containing the files to add, 1 per line.
|
---|
1975 | * @param flag_em If TRUE, then flag the added files for restoration.
|
---|
1976 | * @return 0 for success, nonzero for failure.
|
---|
1977 | */
|
---|
1978 | int add_list_of_files_to_filelist(struct s_node *filelist,
|
---|
1979 | char *list_of_files_fname, bool flag_em)
|
---|
1980 | {
|
---|
1981 | FILE *fin;
|
---|
1982 | char *tmp;
|
---|
1983 | struct s_node *nod;
|
---|
1984 |
|
---|
1985 | malloc_string(tmp);
|
---|
1986 | log_msg(3, "Adding %s to filelist", list_of_files_fname);
|
---|
1987 | if (!(fin = fopen(list_of_files_fname, "r"))) {
|
---|
1988 | iamhere(list_of_files_fname);
|
---|
1989 | return (1);
|
---|
1990 | }
|
---|
1991 | for (fgets(tmp, MAX_STR_LEN, fin); !feof(fin);
|
---|
1992 | fgets(tmp, MAX_STR_LEN, fin)) {
|
---|
1993 | if (!tmp[0]) {
|
---|
1994 | continue;
|
---|
1995 | }
|
---|
1996 | if ((tmp[strlen(tmp) - 1] == 13 || tmp[strlen(tmp) - 1] == 10)
|
---|
1997 | && strlen(tmp) > 0) {
|
---|
1998 | tmp[strlen(tmp) - 1] = '\0';
|
---|
1999 | }
|
---|
2000 | log_msg(2, "tmp = '%s'", tmp);
|
---|
2001 | if (!tmp[0]) {
|
---|
2002 | continue;
|
---|
2003 | }
|
---|
2004 | if ((nod = find_string_at_node(filelist, tmp))) {
|
---|
2005 | log_msg(5, "Found '%s' in filelist already. Cool.", tmp);
|
---|
2006 | } else {
|
---|
2007 | add_string_at_node(filelist, tmp);
|
---|
2008 | nod = find_string_at_node(filelist, tmp);
|
---|
2009 | }
|
---|
2010 |
|
---|
2011 | if (nod && flag_em) {
|
---|
2012 | toggle_path_selection(filelist, tmp, TRUE);
|
---|
2013 | log_msg(5, "Flagged '%s'", tmp);
|
---|
2014 | }
|
---|
2015 | }
|
---|
2016 | paranoid_fclose(fin);
|
---|
2017 | paranoid_free(tmp);
|
---|
2018 | return (0);
|
---|
2019 | }
|
---|
2020 |
|
---|
2021 | /* @} - end of filelistGroup */
|
---|