Changeset 1110 in MondoRescue
- Timestamp:
- Feb 8, 2007, 1:37:30 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/stable/mondo/src/common/libmondo-filelist.c
r1107 r1110 10 10 #include "my-stuff.h" 11 11 #include "mondostructures.h" 12 #include "lib-common-externs.h"13 12 #include "libmondo-filelist.h" 14 13 #include "libmondo-string-EXT.h" 15 14 #include "libmondo-files-EXT.h" 16 15 #include "libmondo-fork-EXT.h" 17 #include " libmondo-gui-EXT.h"16 #include "newt-specific-EXT.h" 18 17 #include "libmondo-tools-EXT.h" 19 18 #include "mr_str.h" … … 68 67 extern char *g_getfattr; 69 68 70 71 72 69 /** 73 70 * @addtogroup filelistGroup … … 89 86 char *filelist; 90 87 char *tempfile; 91 char *cksumlist;92 char *tmp;93 88 long noof_sets; 94 89 … … 100 95 int i, retval = 0; 101 96 102 malloc_string(dev); 103 malloc_string(filelist); 104 malloc_string(tempfile); 105 malloc_string(cksumlist); 106 malloc_string(tmp); 107 mvaddstr_and_log_it(g_currentY, 0, "Dividing filelist into sets"); 108 109 log_to_screen("Dividing filelist into sets. Please wait."); 97 mvaddstr_and_log_it(g_currentY, 0, _("Dividing filelist into sets")); 98 99 log_to_screen(_("Dividing filelist into sets. Please wait.")); 110 100 i = 0; 111 sprintf(filelist, "%s/archives/filelist.full", bkpinfo->scratchdir); 112 sprintf(cksumlist, "%s/cklist.full", bkpinfo->tmpdir); 101 mr_asprintf(&filelist, "%s/archives/filelist.full", bkpinfo->scratchdir); 113 102 if (!does_file_exist(filelist)) { 114 103 log_it("filelist %s not found", filelist); … … 119 108 chop_filelist(filelist, bkpinfo->tmpdir, 120 109 bkpinfo->optimal_set_size); 110 mr_free(filelist); 111 121 112 estimate_noof_media_required(bkpinfo, noof_sets); // for cosmetic purposes 122 113 123 sprintf(tempfile, "%s/biggielist.txt", bkpinfo->tmpdir);114 mr_asprintf(&tempfile, "%s/biggielist.txt", bkpinfo->tmpdir); 124 115 if (!(fout = fopen(tempfile, "a"))) { 125 116 log_OS_error("Cannot append to biggielist"); 126 117 retval++; 127 goto end_of_func;128 }118 } 119 mr_free(tempfile); 129 120 log_it(bkpinfo->image_devs); 130 121 … … 132 123 133 124 while (ptr && *ptr) { 134 strcpy(dev, ptr);125 mr_asprintf(&dev, ptr); 135 126 log_it("Examining imagedev %s", dev); 136 127 for (i = 0; i < (int) strlen(dev) && dev[i] != ' '; i++); … … 141 132 fprintf(fout, "%s\n", dev); 142 133 log_it("Adding '%s' to biggielist", dev); 134 mr_free(dev); 135 143 136 if ((ptr = strchr(ptr, ' '))) { 144 137 ptr++; … … 148 141 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 149 142 150 end_of_func:151 mr_free(filelist);152 mr_free(tempfile);153 mr_free(cksumlist);154 mr_free(dev);155 mr_free(tmp);156 143 return (retval); 157 144 } … … 166 153 167 154 mr_msg(1, "Sorting file %s", orig_fname); 168 malloc_string(tmp_fname); 169 malloc_string(command); 170 sprintf(tmp_fname, "/tmp/sort.%d.%d.%d", (int) (random() % 32768), 171 (int) (random() % 32768), (int) (random() % 32768)); 155 mr_asprintf(&tmp_fname, "/tmp/sort.%d.%d.%d", (int) (random() % 32768), 156 (int) (random() % 32768), (int) (random() % 32768)); 172 157 173 158 if (!does_file_exist(orig_fname)) { … … 175 160 } // no sense in trying to sort an empty file 176 161 177 sprintf(command, "sort %s > %s 2>> %s", orig_fname, tmp_fname,178 MONDO_LOGFILE);162 mr_asprintf(&command, "sort %s > %s 2>> %s", orig_fname, tmp_fname, 163 MONDO_LOGFILE); 179 164 retval = system(command); 165 mr_free(command); 166 180 167 if (retval) { 181 168 mr_msg(2, "Failed to sort %s - oh dear", orig_fname); … … 183 170 mr_msg(2, "Sorted %s --> %s OK. Copying it back to %s now", 184 171 orig_fname, tmp_fname, orig_fname); 185 sprintf(command, "mv -f %s %s", tmp_fname, orig_fname);172 mr_asprintf(&command, "mv -f %s %s", tmp_fname, orig_fname); 186 173 retval += run_program_and_log_output(command, 2); 174 mr_free(command); 175 187 176 if (retval) { 188 177 mr_msg(2, "Failed to copy %s back to %s - oh dear", tmp_fname, … … 193 182 } 194 183 mr_free(tmp_fname); 195 mr_free(command);196 184 mr_msg(1, "Finished sorting file %s", orig_fname); 197 185 return (retval); 198 186 } 199 200 187 201 188 … … 223 210 /*@ int **************************************** */ 224 211 int i; 212 size_t n = 0; 225 213 long curr_set_no; 226 214 … … 228 216 char *outfname; 229 217 char *biggie_fname; 230 char *incoming ;218 char *incoming = NULL; 231 219 char *tmp; 232 char *acl_fname;233 char *xattr_fname;234 220 235 221 /*@ pointers *********************************** */ … … 242 228 int err = 0; 243 229 244 malloc_string(outfname);245 malloc_string(biggie_fname);246 incoming = mr_malloc(MAX_STR_LEN * 2);247 malloc_string(tmp);248 malloc_string(acl_fname);249 malloc_string(xattr_fname);250 230 251 231 assert_string_is_neither_NULL_nor_zerolength(filelist); … … 267 247 curr_set_no = 0; 268 248 curr_set_size = 0; 269 sprintf(outfname, "%s/filelist.%ld", outdir, curr_set_no);270 sprintf(biggie_fname, "%s/biggielist.txt", outdir);249 mr_asprintf(&outfname, "%s/filelist.%ld", outdir, curr_set_no); 250 mr_asprintf(&biggie_fname, "%s/biggielist.txt", outdir); 271 251 log_it("outfname=%s; biggie_fname=%s", outfname, biggie_fname); 272 252 if (!(fbig = fopen(biggie_fname, "w"))) { … … 280 260 goto end_of_func; 281 261 } 282 (void) fgets(incoming, MAX_STR_LEN * 2 - 1, fin);262 mr_getline(&incoming, &n, fin); 283 263 while (!feof(fin)) { 284 264 lino++; … … 286 266 if (i < 0) { 287 267 i = 0; 288 }289 if (i > MAX_STR_LEN - 1) {290 incoming[MAX_STR_LEN - 30] = '\0';291 mr_msg(1, "Warning - truncating file %s's name", incoming);292 err++;293 268 } 294 269 if (incoming[i] < 32) { … … 312 287 paranoid_fclose(fout); 313 288 sort_file(outfname); 289 mr_free(outfname); 290 314 291 curr_set_no++; 315 292 curr_set_size = 0; 316 sprintf(outfname, "%s/filelist.%ld", outdir, curr_set_no); 293 mr_asprintf(&outfname, "%s/filelist.%ld", outdir, 294 curr_set_no); 317 295 if (!(fout = fopen(outfname, "w"))) { 318 296 log_OS_error("Unable to openout outfname"); … … 320 298 goto end_of_func; 321 299 } 322 sprintf(tmp, "Fileset #%ld chopped ", curr_set_no - 1);323 300 update_evalcall_form((int) (lino * 100 / noof_lines)); 324 /* if (!g_text_mode) {newtDrawRootText(0,22,tmp);newtRefresh();} else {log_it(tmp);} */325 301 } 326 302 } 327 (void) fgets(incoming, MAX_STR_LEN * 2 - 1, fin);303 mr_getline(&incoming, &n, fin); 328 304 } 329 305 paranoid_fclose(fin); … … 338 314 sort_file(outfname); 339 315 sort_file(biggie_fname); 340 sprintf(outfname, "%s/LAST-FILELIST-NUMBER", outdir); 341 sprintf(tmp, "%ld", curr_set_no); 316 mr_free(biggie_fname); 317 mr_free(outfname); 318 319 mr_asprintf(&outfname, "%s/LAST-FILELIST-NUMBER", outdir); 320 mr_asprintf(&tmp, "%ld", curr_set_no); 342 321 if (write_one_liner_data_file(outfname, tmp)) { 343 322 log_OS_error … … 345 324 err = 1; 346 325 } 326 mr_free(outfname); 327 mr_free(tmp); 328 347 329 if (curr_set_no == 0) { 348 sprintf(tmp, "Only one fileset. Fine.");330 mr_asprintf(&tmp, "Only one fileset. Fine."); 349 331 } else { 350 sprintf(tmp, "Filelist divided into %ld sets", curr_set_no + 1);332 mr_asprintf(&tmp, "Filelist divided into %ld sets", curr_set_no + 1); 351 333 } 352 334 mr_msg(1, tmp); 335 mr_free(tmp); 353 336 close_evalcall_form(); 354 337 /* This is to work around an obscure bug in Newt; open a form, close it, … … 365 348 #endif 366 349 end_of_func: 367 mr_free(outfname);368 mr_free(biggie_fname);369 mr_free(incoming);370 mr_free(tmp);371 mr_free(acl_fname);372 mr_free(xattr_fname);373 350 return (err ? 0 : curr_set_no + 1); 374 351 } 375 376 377 378 352 379 353 … … 397 371 if (depth == 0) { 398 372 open_evalcall_form("Freeing memory"); 399 log_to_screen( "Freeing memory formerly occupied by filelist");373 log_to_screen(_("Freeing memory formerly occupied by filelist")); 400 374 } 401 375 depth++; … … 420 394 } 421 395 filelist->ch = '\0'; 422 mr_free((void *)filelist);396 mr_free((void *)filelist); 423 397 depth--; 424 398 if (depth == 0) { … … 432 406 { 433 407 FILE *pattr; 434 char *tmp; 408 char *tmp = NULL; 409 size_t n = 0; 410 435 411 pattr = popen(sys_call, "r"); 436 412 if (!pattr) { … … 443 419 return (2); 444 420 } 445 malloc_string(tmp); 446 for (fgets(tmp, MAX_STR_LEN, pattr); !feof(pattr); 447 fgets(tmp, MAX_STR_LEN, pattr)) { 421 for (mr_getline(&tmp, &n, pattr); !feof(pattr); mr_getline(&tmp, &n, pattr)) { 448 422 fputs(tmp, pout); 449 423 } … … 452 426 return (0); 453 427 } 454 455 428 456 429 … … 462 435 char *pout_command; 463 436 char *sys_call; 464 char *file_to_analyze ;437 char *file_to_analyze = NULL; 465 438 char *strtmp = NULL; 466 439 int i; 440 size_t n = 0; 467 441 468 442 if (!(fin = fopen(filelist, "r"))) { … … 470 444 return (1); 471 445 } 472 malloc_string(pout_command); 473 sprintf(pout_command, "gzip -c1 > %s", auxlist_fname); 446 mr_asprintf(&pout_command, "gzip -c1 > %s", auxlist_fname); 474 447 if (!(pout = popen(pout_command, "w"))) { 475 448 mr_msg(1, "Cannot openout auxlist_fname %s", auxlist_fname); … … 478 451 return (4); 479 452 } 480 malloc_string(file_to_analyze); 481 for (fgets(file_to_analyze, MAX_STR_LEN, fin); !feof(fin); 482 fgets(file_to_analyze, MAX_STR_LEN, fin)) { 453 mr_free(pout_command); 454 455 for (mr_getline(&file_to_analyze, &n, fin); !feof(fin); 456 mr_getline(&file_to_analyze, &n, fin)) { 483 457 i = strlen(file_to_analyze); 484 458 if (i > 0 && file_to_analyze[i - 1] < 32) { … … 486 460 } 487 461 mr_msg(8, "Analyzing %s", file_to_analyze); 488 asprintf(&strtmp, syscall_sprintf, mr_stresc(file_to_analyze, "`$\\\"", '\\')); 489 asprintf(&sys_call, "%s 2>> /dev/null", strtmp); // " MONDO_LOGFILE); 462 /* BERLIOS : to be checked */ 463 mr_asprintf(&strtmp, syscall_sprintf, mr_stresc(file_to_analyze, "`$\\\"", '\\')); 464 mr_asprintf(&sys_call, "%s 2>> /dev/null", strtmp); 490 465 mr_free(strtmp); 491 466 call_exe_and_pipe_output_to_fd(sys_call, pout); … … 495 470 paranoid_pclose(pout); 496 471 mr_free(file_to_analyze); 497 mr_free(pout_command);498 472 return (0); 499 473 } … … 502 476 int get_acl_list(char *filelist, char *facl_fname) 503 477 { 504 char *command ;478 char *command = NULL; 505 479 int retval = 0; 506 480 507 481 if (g_getfacl != NULL) { 508 malloc_string(command); 509 sprintf(command, "touch %s", facl_fname); 482 mr_asprintf(&command, "touch %s", facl_fname); 510 483 run_program_and_log_output(command, 8); 511 // sort_file(filelist); // FIXME - filelist chopper sorts, so this isn't necessary 512 sprintf(command, 513 "getfacl --all-effective -P %s 2>> %s | gzip -c1 > %s 2>> %s", 514 filelist, MONDO_LOGFILE, facl_fname, MONDO_LOGFILE); 484 mr_free(command); 485 486 mr_asprintf(&command, 487 "getfacl --all-effective -P %s 2>> %s | gzip -c1 > %s 2>> %s", 488 filelist, MONDO_LOGFILE, facl_fname, MONDO_LOGFILE); 515 489 iamhere(command); 516 490 retval = system(command); … … 523 497 int get_fattr_list(char *filelist, char *fattr_fname) 524 498 { 525 char *command ;499 char *command = NULL; 526 500 int retval = 0; 527 501 528 502 if (g_getfattr != NULL) { 529 malloc_string(command); 530 sprintf(command, "touch %s", fattr_fname); 503 mr_asprintf(&command, "touch %s", fattr_fname); 531 504 run_program_and_log_output(command, 8); 532 505 mr_free(command); 533 // sort_file(filelist); // FIXME - filelist chopper sorts, so this isn't necessary 506 534 507 retval = 535 508 gen_aux_list(filelist, "getfattr --en=hex -P -d \"%s\"", … … 544 517 { 545 518 const int my_depth = 8; 546 char *command, *syscall_pin, *syscall_pout, *incoming; 547 char *current_subset_file, *current_master_file, *masklist; 519 char *command, *syscall_pin, *syscall_pout; 520 char *incoming = NULL; 521 char *current_subset_file = NULL; 522 char *current_master_file, *masklist; 548 523 int retval = 0; 549 524 int i; 525 size_t n = 0; 550 526 char *p, *q; 551 527 FILE *pin, *pout, *faclin; 552 528 553 malloc_string(command);554 529 mr_msg(1, "set_EXAT_list(%s, %s, %s)", orig_msklist, 555 530 original_exat_fname, executable); … … 558 533 mr_msg(1, 559 534 "No masklist provided. I shall therefore set ALL attributes."); 560 sprintf(command, "gzip -dc %s | %s --restore - 2>> %s",561 original_exat_fname, executable, MONDO_LOGFILE);535 mr_asprintf(&command, "gzip -dc %s | %s --restore - 2>> %s", 536 original_exat_fname, executable, MONDO_LOGFILE); 562 537 mr_msg(1, "command = %s", command); 563 538 retval = system(command); … … 570 545 "original_exat_fname %s is empty or missing, so no need to set EXAT list", 571 546 original_exat_fname); 572 mr_free(command);573 547 return (0); 574 548 } 575 malloc_string(incoming); 576 malloc_string(masklist); 577 malloc_string(current_subset_file); 578 malloc_string(current_master_file); 579 malloc_string(syscall_pin); 580 malloc_string(syscall_pout); 581 sprintf(masklist, "/tmp/%d.%d.mask", (int) (random() % 32768), 582 (int) (random() % 32768)); 583 sprintf(command, "cp -f %s %s", orig_msklist, masklist); 549 mr_asprintf(&masklist, "/tmp/%d.%d.mask", (int) (random() % 32768), 550 (int) (random() % 32768)); 551 552 mr_asprintf(&command, "cp -f %s %s", orig_msklist, masklist); 584 553 run_program_and_log_output(command, 1); 554 mr_free(command); 555 585 556 sort_file(masklist); 586 current_subset_file[0] = current_master_file[0] = '\0'; 587 sprintf(syscall_pin, "gzip -dc %s", original_exat_fname); 588 sprintf(syscall_pout, "%s --restore - 2>> %s", executable, 589 MONDO_LOGFILE); 557 mr_asprintf(&syscall_pin, "gzip -dc %s", original_exat_fname); 558 mr_asprintf(&syscall_pout, "%s --restore - 2>> %s", executable, 559 MONDO_LOGFILE); 590 560 591 561 mr_msg(1, "syscall_pin = %s", syscall_pin); … … 596 566 return (1); 597 567 } 568 mr_free(syscall_pout); 569 598 570 pin = popen(syscall_pin, "r"); 599 571 if (!pin) { … … 602 574 return (1); 603 575 } 576 mr_free(syscall_pin); 577 604 578 faclin = fopen(masklist, "r"); 605 579 if (!faclin) { … … 611 585 // printf("Hi there. Starting the loop\n"); 612 586 613 fgets(current_subset_file, MAX_STR_LEN, faclin);614 fgets(incoming, MAX_STR_LEN, pin);587 mr_getline(¤t_subset_file, &n, faclin); 588 mr_getline(&incoming, &n, pin); 615 589 while (!feof(pin) && !feof(faclin)) { 616 590 // printf("incoming = %s", incoming); 617 591 618 strcpy(current_master_file, incoming + 8);592 mr_asprintf(¤t_master_file, incoming + 8); 619 593 620 594 p = current_subset_file; … … 644 618 if (i < 0) { // read another subset file in. 645 619 mr_msg(my_depth, "Reading next subset line in\n\n"); 646 fgets(current_subset_file, MAX_STR_LEN, faclin);620 mr_getline(¤t_subset_file, &n, faclin); 647 621 continue; 648 622 } … … 651 625 fputs(incoming, pout); 652 626 } 653 fgets(incoming, MAX_STR_LEN, pin);627 mr_getline(&incoming, &n, pin); 654 628 if (!i) { 655 629 mr_msg(my_depth, "Copying master %s", q); … … 664 638 fputs(incoming, pout); 665 639 } 666 fgets(incoming, MAX_STR_LEN, pin);640 mr_getline(&incoming, &n, pin); 667 641 } 668 642 if (!i) { 669 fgets(current_subset_file, MAX_STR_LEN, faclin); 670 } 671 } 643 mr_getline(¤t_subset_file, &n, faclin); 644 } 645 mr_free(current_master_file); 646 } 647 mr_free(current_subset_file); 648 672 649 while (!feof(pin)) { 673 fgets(incoming, MAX_STR_LEN, pin); 674 } 650 mr_getline(&incoming, &n, pin); 651 } 652 mr_free(incoming); 675 653 fclose(faclin); 676 654 pclose(pin); … … 680 658 681 659 unlink(masklist); 682 mr_free(current_subset_file);683 mr_free(current_master_file);684 mr_free(syscall_pout);685 mr_free(syscall_pin);686 660 mr_free(masklist); 687 mr_free(incoming); 688 mr_free(command); 661 689 662 return (retval); 690 663 } … … 724 697 /*@ buffers ***************************************************** */ 725 698 char val_sz[MAX_STR_LEN]; 726 char cfg_fname[MAX_STR_LEN]; 727 /* char tmp[MAX_STR_LEN]; remove stan benoit apr 2002 */ 699 char *cfg_fname = NULL; 728 700 729 701 /*@ long ******************************************************** */ 730 int val_i ;702 int val_i = 0; 731 703 732 704 /*@ end vars **************************************************** */ … … 734 706 assert(bkpinfo != NULL); 735 707 736 sprintf(cfg_fname, "%s/mondo-restore.cfg", bkpinfo->tmpdir);708 mr_asprintf(&cfg_fname, "%s/mondo-restore.cfg", bkpinfo->tmpdir); 737 709 read_cfg_var(cfg_fname, "last-filelist-number", val_sz); 738 710 val_i = atoi(val_sz); … … 740 712 val_i = 500; 741 713 } 714 mr_free(cfg_fname); 742 715 return (val_i); 743 716 } … … 751 724 * @bug I don't understand this function. Would someone care to explain it? 752 725 */ 726 753 727 int add_string_at_node(struct s_node *startnode, char *string_to_add) 754 728 { 755 729 756 757 /*@ int ******************************************************** */758 730 int noof_chars; 759 731 int i; 760 732 int res; 761 733 762 /*@ sturctures ************************************************* */763 734 struct s_node *node, *newnode; 764 735 765 /*@ char ****************************************************** */766 736 char char_to_add; 767 768 /*@ bools ****************************************************** */769 737 770 738 const bool sosodef = FALSE; … … 780 748 } 781 749 782 noof_chars = strlen(string_to_add) + 1; / * we include the '\0' */783 784 /* walk across tree if necessary */ 750 noof_chars = strlen(string_to_add) + 1; // we include the '\0' 751 752 // walk across tree if necessary 785 753 node = startnode; 786 754 char_to_add = string_to_add[0]; … … 791 759 } 792 760 793 /* walk down tree if appropriate */ 761 // walk down tree if appropriate 794 762 if (node->down != NULL && node->ch == char_to_add) { 795 763 mr_msg(7, "depth=%d char=%c --- going DOWN", depth, char_to_add); … … 805 773 } 806 774 807 /* add here */ 775 // add here 808 776 newnode = (struct s_node *) mr_malloc(sizeof(struct s_node)); 809 777 if (char_to_add < node->ch) // add to the left of node … … 829 797 return (0); 830 798 } 831 // add the rest799 // add the rest 832 800 mr_msg(6, "Adding remaining chars ('%s')", string_to_add + 1); 833 801 for (i = 1; i < noof_chars; i++) { … … 848 816 849 817 850 851 852 818 /** 853 819 * Load a filelist into a <tt>struct s_node</tt>. … … 859 825 { 860 826 861 /*@ structures ************************************************* */ 862 struct s_node *filelist; 863 864 /*@ pointers *************************************************** */ 865 FILE *pin; 866 867 /*@ buffers **************************************************** */ 868 char command_to_open_fname[MAX_STR_LEN]; 869 char fname[MAX_STR_LEN]; 870 char tmp[MAX_STR_LEN]; 871 int pos_in_fname; 872 /*@ int ******************************************************** */ 873 int percentage; 874 875 /*@ long ******************************************************* */ 876 long lines_in_filelist; 877 long lino = 0; 878 /*@ end vars *************************************************** */ 827 struct s_node *filelist = NULL; 828 FILE *pin = NULL; 829 char *command_to_open_fname = NULL; 830 char *fname = NULL; 831 char *tmp = NULL; 832 char *tmp1 = NULL; 833 int pos_in_fname = 0; 834 size_t n = 0; 835 int percentage = 0; 836 837 long lines_in_filelist = 0L; 838 long lino = 0L; 879 839 880 840 assert_string_is_neither_NULL_nor_zerolength(filelist_fname); … … 883 843 fatal_error("filelist does not exist -- cannot load it"); 884 844 } 885 log_to_screen( "Loading filelist");886 sprintf(command_to_open_fname, "gzip -dc %s", filelist_fname);887 sprintf(tmp, "zcat %s | wc -l", filelist_fname);845 log_to_screen(_("Loading filelist")); 846 mr_asprintf(&command_to_open_fname, "gzip -dc %s", filelist_fname); 847 mr_asprintf(&tmp, "zcat %s | wc -l", filelist_fname); 888 848 mr_msg(6, "tmp = %s", tmp); 889 849 lines_in_filelist = 890 850 atol(call_program_and_get_last_line_of_output(tmp)); 891 851 if (lines_in_filelist < 3) { 892 log_to_screen( "Warning - surprisingly short filelist.");852 log_to_screen(_("Warning - surprisingly short filelist.")); 893 853 } 894 854 g_original_noof_lines_in_filelist = lines_in_filelist; … … 905 865 return (NULL); 906 866 } 907 open_evalcall_form("Loading filelist from disk"); 908 for (fgets(fname, MAX_STR_LEN, pin); !feof(pin); 909 fgets(fname, MAX_STR_LEN, pin)) { 867 mr_free(command_to_open_fname); 868 869 open_evalcall_form(_("Loading filelist from disk")); 870 for (mr_getline(&fname, &n, pin); !feof(pin); mr_getline(&fname, &n, pin)) { 910 871 if ((fname[strlen(fname) - 1] == 13 911 872 || fname[strlen(fname) - 1] == 10) && strlen(fname) > 0) { 912 873 fname[strlen(fname) - 1] = '\0'; 913 874 } 914 // strip_spaces (fname);915 875 if (!strlen(fname)) { 916 876 continue; … … 920 880 continue; 921 881 } 922 strcpy(tmp, fname);882 mr_asprintf(&tmp, fname); 923 883 tmp[pos_in_fname] = '\0'; 924 884 if (strlen(tmp)) { 925 885 add_string_at_node(filelist, tmp); 926 886 } 887 mr_free(tmp); 927 888 } 928 889 add_string_at_node(filelist, fname); … … 932 893 } 933 894 } 895 mr_free(fname); 934 896 paranoid_pclose(pin); 935 897 close_evalcall_form(); … … 976 938 977 939 978 979 980 940 /** 981 941 * Reset the filelist to the state it was when it was loaded. This does not … … 992 952 993 953 994 995 954 /** 996 955 * Save a filelist tree structure to disk. … … 1022 981 assert(outfname != NULL); // will be zerolength if save_filelist() is called by itself 1023 982 if (depth == 0) { 1024 log_to_screen( "Saving filelist");983 log_to_screen(_("Saving filelist")); 1025 984 if (!(fout = fopen(outfname, "w"))) { 1026 985 fatal_error("Cannot openout/save filelist"); 1027 986 } 1028 987 lines_in_filelist = g_original_noof_lines_in_filelist; /* set by load_filelist() */ 1029 open_evalcall_form( "Saving selection to disk");988 open_evalcall_form(_("Saving selection to disk")); 1030 989 } 1031 990 for (node = filelist; node != NULL; node = node->right) { … … 1056 1015 1057 1016 1058 1059 1017 /** 1060 1018 * Toggle all root dirs on. … … 1124 1082 /*@ buffers **************************************************** */ 1125 1083 static char current_filename[MAX_STR_LEN]; 1126 1127 /* char tmp[MAX_STR_LEN+2]; */1128 1084 1129 1085 /*@ end vars *************************************************** */ … … 1179 1135 } 1180 1136 1137 1181 1138 /** 1182 1139 * Toggle whether a path is selected. … … 1199 1156 /*@ buffers ***************************************************** */ 1200 1157 static char current_filename[MAX_STR_LEN]; 1201 char tmp[MAX_STR_LEN + 2];1202 1158 1203 1159 /*@ end vars *************************************************** */ … … 1222 1178 || current_filename[j] == '\0') { 1223 1179 node->selected = on_or_off; 1224 sprintf(tmp, "%s is now %s\n", current_filename,1225 (on_or_off ? "ON" : "OFF"));1226 1180 } 1227 1181 } … … 1259 1213 } 1260 1214 } 1261 1262 1263 1264 1265 1266 1215 1267 1216 … … 1299 1248 if (bkpinfo->make_filelist) { 1300 1249 mvaddstr_and_log_it(g_currentY, 0, 1301 "Making catalog of files to be backed up");1250 _("Making catalog of files to be backed up")); 1302 1251 } else { 1303 1252 mvaddstr_and_log_it(g_currentY, 0, 1304 "Using supplied catalog of files to be backed up");1253 _("Using supplied catalog of files to be backed up")); 1305 1254 } 1306 1255 … … 1322 1271 if (res) { 1323 1272 log_OS_error("Call to mondo_makefilelist failed"); 1324 mvaddstr_and_log_it(g_currentY++, 74, "Failed.");1273 mvaddstr_and_log_it(g_currentY++, 74, _("Failed.")); 1325 1274 } else { 1326 mvaddstr_and_log_it(g_currentY++, 74, "Done.");1275 mvaddstr_and_log_it(g_currentY++, 74, _("Done.")); 1327 1276 } 1328 1277 return (res); … … 1343 1292 { 1344 1293 const char delims[] = " "; 1345 1346 DIR *dip;1347 struct dirent *dit; 1294 DIR *dip = NULL; 1295 struct dirent *dit = NULL; 1296 1348 1297 struct stat statbuf; 1349 1298 char new[MAX_STR_LEN]; 1350 char *tmp ;1351 char *sth_B ;1299 char *tmp = NULL; 1300 char *sth_B = NULL; 1352 1301 static int percentage = 0; 1353 char *ith_B ;1354 char *skip_these ;1355 char *new_with_spaces ;1356 char *strtmp;1357 char *token;1358 char * find_excludes;1359 static char *name_of_evalcall_form;1360 int i;1302 char *ith_B = NULL; 1303 char *skip_these = NULL; 1304 char *new_with_spaces = NULL; 1305 static char *name_of_evalcall_form = NULL; 1306 int i = 0; 1307 char *strtmp = NULL; 1308 char *token = NULL; 1309 char *find_excludes = NULL; 1361 1310 int lastpos = 0; 1362 1311 static int depth = 0; 1363 char *p ;1312 char *p = NULL; 1364 1313 static int counter = 0; 1365 1314 static int uberctr = 0; 1366 static char *find_skeleton_marker ;1315 static char *find_skeleton_marker = NULL; 1367 1316 static long skeleton_lino = 0; 1368 1317 static time_t last_time = 0; … … 1523 1472 1524 1473 1525 1526 1474 /** 1527 1475 * Get the next entry in the space-separated list in @p incoming. … … 1535 1483 { 1536 1484 static char sz_res[MAX_STR_LEN]; 1537 char *p ;1485 char *p = NULL; 1538 1486 bool in_quotes = FALSE; 1539 1487 … … 1549 1497 return (sz_res); 1550 1498 } 1551 1552 1499 1553 1500 … … 1570 1517 { 1571 1518 char sz_datefile_wildcard[] = "/var/cache/mondo-archive/difflevel.%d"; 1572 char *p, *q; 1573 char sz_datefile[80]; 1574 char *sz_filelist, *exclude_paths, *tmp; 1575 int i; 1576 FILE *fout; 1577 char *command; 1519 char *p = NULL; 1520 char *q = NULL; 1521 1522 char *tmp1 = NULL; 1523 char *tmp2 = NULL; 1524 char *sz_datefile = NULL; 1525 char *sz_filelist = NULL; 1526 char *exclude_paths = NULL; 1527 int i = 0; 1528 FILE *fout = NULL; 1529 char *command = NULL; 1578 1530 time_t time_of_last_full_backup = 0; 1579 1531 struct stat statbuf; 1580 1532 1581 malloc_string(command); 1582 malloc_string(tmp); 1583 malloc_string(sz_filelist); 1533 malloc_string(sz_datefile); 1534 malloc_string(exclude_paths); 1584 1535 malloc_string(g_skeleton_filelist); 1585 exclude_paths = mr_malloc(1000); 1586 mr_msg(3, "Trying to write test string to exclude_paths"); 1587 strcpy(exclude_paths, "/blah /froo"); 1588 mr_msg(3, "...Success!"); 1589 sprintf(sz_datefile, sz_datefile_wildcard, 0); 1536 // The pathname to the skeleton filelist, used to give better progress reporting for mondo_makefilelist(). 1537 mr_asprintf(&sz_datefile, sz_datefile_wildcard, 0); 1590 1538 if (!include_paths && !userdef_filelist) { 1591 1539 fatal_error … … 1593 1541 } 1594 1542 // make hole for filelist 1595 sprintf(command, "mkdir -p %s/archives", scratchdir);1543 mr_asprintf(&command, "mkdir -p %s/archives", scratchdir); 1596 1544 paranoid_system(command); 1597 sprintf(sz_filelist, "%s/tmpfs/filelist.full", tmpdir); 1545 mr_free(command); 1546 1547 mr_asprintf(&sz_filelist, "%s/tmpfs/filelist.full", tmpdir); 1598 1548 make_hole_for_file(sz_filelist); 1599 1549 1600 1550 if (differential == 0) { 1601 1551 // restore last good datefile if it exists 1602 sprintf(command, "cp -f %s.aborted %s", sz_datefile, sz_datefile); 1552 mr_asprintf(&command, "cp -f %s.aborted %s", sz_datefile, 1553 sz_datefile); 1603 1554 run_program_and_log_output(command, 3); 1555 mr_free(command); 1556 1604 1557 // backup last known good datefile just in case :) 1605 1558 if (does_file_exist(sz_datefile)) { 1606 sprintf(command, "mv -f %s %s.aborted", sz_datefile,1607 sz_datefile);1559 mr_asprintf(&command, "mv -f %s %s.aborted", sz_datefile, 1560 sz_datefile); 1608 1561 paranoid_system(command); 1562 mr_free(command); 1609 1563 } 1610 1564 make_hole_for_file(sz_datefile); … … 1621 1575 mr_msg(2, "Differential backup. Yay."); 1622 1576 } 1577 mr_free(sz_datefile); 1623 1578 1624 1579 // use user-specified filelist (if specified) … … 1627 1582 "Using the user-specified filelist - %s - instead of calculating one", 1628 1583 userdef_filelist); 1629 sprintf(command, "cp -f %s %s", userdef_filelist, sz_filelist);1584 mr_asprintf(&command, "cp -f %s %s", userdef_filelist, sz_filelist); 1630 1585 if (run_program_and_log_output(command, 3)) { 1631 1586 fatal_error("Failed to copy user-specified filelist"); 1632 1587 } 1588 mr_free(command); 1633 1589 } else { 1634 1590 mr_msg(2, "include_paths = '%s'", include_paths); … … 1667 1623 } 1668 1624 paranoid_fclose(fout); 1625 mr_free(exclude_paths); 1669 1626 } 1670 1627 mr_msg(2, "Copying new filelist to scratchdir"); 1671 sprintf(command, "mkdir -p %s/archives", scratchdir);1628 mr_asprintf(&command, "mkdir -p %s/archives", scratchdir); 1672 1629 paranoid_system(command); 1673 sprintf(command, "cp -f %s %s/archives/", sz_filelist, scratchdir); 1630 mr_free(command); 1631 1632 mr_asprintf(&command, "cp -f %s %s/archives/", sz_filelist, scratchdir); 1674 1633 paranoid_system(command); 1675 sprintf(command, "mv -f %s %s", sz_filelist, tmpdir); 1634 mr_free(command); 1635 1636 mr_asprintf(&command, "mv -f %s %s", sz_filelist, tmpdir); 1676 1637 paranoid_system(command); 1677 mr_ msg(2, "Freeing variables");1638 mr_free(command); 1678 1639 mr_free(sz_filelist); 1679 mr_free(command);1680 mr_free(exclude_paths);1681 mr_free(tmp);1682 1640 mr_free(g_skeleton_filelist); 1683 1641 mr_msg(2, "Exiting"); 1684 1642 return (0); 1685 1643 } 1686 1687 1688 1644 1689 1645 … … 1750 1706 1751 1707 1752 1753 1708 /** 1754 1709 * Write all entries in @p needles_list_fname which are also in … … 1768 1723 FILE *fin; 1769 1724 FILE *fout; 1770 char *fname ;1725 char *fname = NULL; 1771 1726 char *tmp; 1772 1727 size_t len = 0; // Scrub's patch doesn't work without that 1773 1728 1774 // mr_msg(1, "use_star = %s", (use_star)?"TRUE":"FALSE");1775 malloc_string(fname);1776 malloc_string(tmp);1777 1729 mr_msg(5, "starting"); 1778 1730 mr_msg(5, "needles_list_fname = %s", needles_list_fname); … … 1785 1737 } 1786 1738 while (!feof(fin)) { 1787 // fscanf(fin, "%s\n", fname); 1788 len = MAX_STR_LEN - 1; 1789 getline(&fname, &len, fin); // patch by Scrub 1739 mr_getline(&fname, &len, fin); 1790 1740 if (!use_star) { 1791 1741 if (fname[0] == '/') { 1792 strcpy(tmp, fname);1742 mr_asprintf(&tmp, fname); 1793 1743 } else { 1794 tmp[0] = '/'; 1795 strcpy(tmp + 1, fname); 1744 mr_asprintf(&tmp, "/%s", fname); 1796 1745 } 1797 strcpy(fname, tmp); 1746 mr_free(fname); 1747 fname = tmp; 1798 1748 } 1799 1749 while (strlen(fname) > 0 && fname[strlen(fname) - 1] < 32) { 1800 1750 fname[strlen(fname) - 1] = '\0'; 1801 1751 } 1802 1803 /*1804 if (strlen(fname)>3 && fname[strlen(fname)-1]=='/') { fname[strlen(fname)-1] = '\0'; }1805 if (strlen(fname)==0) { continue; }1806 sprintf(temporary_string, "echo \"Looking for '%s'\" >> /tmp/looking.txt", fname);1807 system(temporary_string);1808 */1809 1752 1810 1753 mr_msg(5, "Looking for '%s'", fname); … … 1812 1755 if (found_node) { 1813 1756 if (found_node->selected) { 1814 // if (use_star)1815 1757 if (fname[0] == '/') { 1816 strcpy(tmp, fname + 1); 1817 strcpy(fname, tmp); 1758 mr_asprintf(&tmp, fname + 1); 1759 mr_free(fname); 1760 fname = tmp; 1818 1761 } 1819 1762 mr_msg(5, "Found '%s'", fname); 1820 1763 turn_wildcard_chars_into_literal_chars(tmp, fname); 1821 1764 fprintf(fout, "%s\n", tmp); 1765 mr_free(tmp); 1822 1766 retval++; 1823 1767 } 1824 1768 } 1769 mr_free(fname); 1825 1770 } 1826 1771 paranoid_fclose(fout); 1827 1772 paranoid_fclose(fin); 1828 mr_free(fname);1829 mr_free(tmp);1830 1773 return (retval); 1831 1774 } 1832 1833 1834 1835 1836 1775 1837 1776 … … 1848 1787 { 1849 1788 FILE *fin; 1850 char *tmp; 1789 char *tmp = NULL; 1790 size_t n = 0; 1851 1791 struct s_node *nod; 1852 1792 1853 malloc_string(tmp);1854 1793 mr_msg(3, "Adding %s to filelist", list_of_files_fname); 1855 1794 if (!(fin = fopen(list_of_files_fname, "r"))) { … … 1857 1796 return (1); 1858 1797 } 1859 for (fgets(tmp, MAX_STR_LEN, fin); !feof(fin); 1860 fgets(tmp, MAX_STR_LEN, fin)) { 1798 for (mr_getline(&tmp, &n, fin); !feof(fin); mr_getline(&tmp, &n, fin)) { 1861 1799 if (!tmp[0]) { 1862 1800 continue;
Note:
See TracChangeset
for help on using the changeset viewer.