X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=bacula%2Fsrc%2Ftools%2Ftestfind.c;h=e72fb045ab2a3dd64493fb63612dc5e7acb33dde;hb=b8038c40fc96befe1137a75438158f98eeb93399;hp=61e64a271780ab1a24c60f92bde3fdaa581a1f9e;hpb=97858996d6b266e88c107716a457f4d39b235f2a;p=bacula%2Fbacula diff --git a/bacula/src/tools/testfind.c b/bacula/src/tools/testfind.c index 61e64a2717..e72fb045ab 100644 --- a/bacula/src/tools/testfind.c +++ b/bacula/src/tools/testfind.c @@ -1,4 +1,4 @@ -/* +/* * Test program for find files */ @@ -82,30 +82,30 @@ main (int argc, char *const *argv) while ((ch = getopt(argc, argv, "ad:e:i:?")) != -1) { switch (ch) { - case 'a': /* print extended attributes *debug* */ + case 'a': /* print extended attributes *debug* */ attrs = 1; break; - case 'd': /* set debug level */ + case 'd': /* set debug level */ debug_level = atoi(optarg); if (debug_level <= 0) { - debug_level = 1; + debug_level = 1; } break; - case 'e': /* exclude patterns */ + case 'e': /* exclude patterns */ exc = optarg; break; - case 'i': /* include patterns */ + case 'i': /* include patterns */ inc = optarg; break; - case '?': + case '?': default: usage(); - } + } } argc -= optind; argv += optind; @@ -115,22 +115,22 @@ main (int argc, char *const *argv) ff = init_find_files(); if (argc == 0 && !inc) { add_fname_to_include_list(ff, 0, "/"); /* default to / */ - } else { + } else { for (i=0; i < argc; i++) { - if (strcmp(argv[i], "-") == 0) { + if (strcmp(argv[i], "-") == 0) { while (fgets(name, sizeof(name)-1, stdin)) { strip_trailing_junk(name); - add_fname_to_include_list(ff, 0, name); + add_fname_to_include_list(ff, 0, name); } continue; } - add_fname_to_include_list(ff, 0, argv[i]); + add_fname_to_include_list(ff, 0, argv[i]); } } if (inc) { fd = fopen(inc, "r"); if (!fd) { - printf("Could not open include file: %s\n", inc); + printf("Could not open include file: %s\n", inc); exit(1); } while (fgets(name, sizeof(name)-1, fd)) { @@ -143,7 +143,7 @@ main (int argc, char *const *argv) if (exc) { fd = fopen(exc, "r"); if (!fd) { - printf("Could not open exclude file: %s\n", exc); + printf("Could not open exclude file: %s\n", exc); exit(1); } while (fgets(name, sizeof(name)-1, fd)) { @@ -154,17 +154,17 @@ main (int argc, char *const *argv) } find_files(jcr, ff, print_file, NULL); hard_links = term_find_files(ff); - - printf(_("\ -Total files : %d\n\ -Max file length: %d\n\ -Max path length: %d\n\ -Files truncated: %d\n\ -Paths truncated: %d\n\ -Hard links : %d\n"), + + printf(_("" +"Total files : %d\n" +"Max file length: %d\n" +"Max path length: %d\n" +"Files truncated: %d\n" +"Paths truncated: %d\n" +"Hard links : %d\n"), num_files, max_file_len, max_path_len, trunc_fname, trunc_path, hard_links); - + free_jcr(jcr); close_memory_pool(); sm_dump(false); @@ -177,50 +177,60 @@ static int print_file(FF_PKT *ff, void *pkt) switch (ff->type) { case FT_LNKSAVED: if (debug_level == 1) { - printf("%s\n", ff->fname); + printf("%s\n", ff->fname); } else if (debug_level > 1) { - printf("Lnka: %s -> %s\n", ff->fname, ff->link); + printf("Lnka: %s -> %s\n", ff->fname, ff->link); } break; case FT_REGE: if (debug_level == 1) { - printf("%s\n", ff->fname); + printf("%s\n", ff->fname); } else if (debug_level > 1) { - printf("Empty: %s\n", ff->fname); + printf("Empty: %s\n", ff->fname); } count_files(ff); - break; + break; case FT_REG: if (debug_level == 1) { - printf("%s\n", ff->fname); + printf("%s\n", ff->fname); } else if (debug_level > 1) { - printf("Reg: %s\n", ff->fname); + printf("Reg: %s\n", ff->fname); } count_files(ff); break; case FT_LNK: if (debug_level == 1) { - printf("%s\n", ff->fname); + printf("%s\n", ff->fname); } else if (debug_level > 1) { - printf("Lnk: %s -> %s\n", ff->fname, ff->link); + printf("Lnk: %s -> %s\n", ff->fname, ff->link); } count_files(ff); break; case FT_DIRBEGIN: return 1; + case FT_NORECURSE: + case FT_NOFSCHG: + case FT_INVALIDFS: case FT_DIREND: - if (debug_level == 1) { - printf("%s\n", ff->fname); - } else if (debug_level > 1) { - printf("Dir: %s\n", ff->fname); + if (debug_level) { + char errmsg[100] = ""; + if (ff->type == FT_NORECURSE) { + bstrncpy(errmsg, "\t[will not descend: recursion turned off]", sizeof(errmsg)); + } else if (ff->type == FT_NOFSCHG) { + bstrncpy(errmsg, "\t[will not descend: file system change not allowed]", sizeof(errmsg)); + } else if (ff->type == FT_INVALIDFS) { + bstrncpy(errmsg, "\t[will not descend: disallowed file system]", sizeof(errmsg)); + } + printf("%s%s%s\n", (debug_level > 1 ? "Dir: " : ""), ff->fname, errmsg); } + ff->type = FT_DIREND; count_files(ff); break; case FT_SPEC: if (debug_level == 1) { - printf("%s\n", ff->fname); + printf("%s\n", ff->fname); } else if (debug_level > 1) { - printf("Spec: %s\n", ff->fname); + printf("Spec: %s\n", ff->fname); } count_files(ff); break; @@ -239,12 +249,6 @@ static int print_file(FF_PKT *ff, void *pkt) case FT_ISARCH: printf(_("Err: Attempt to backup archive. Not saved. %s\n"), ff->fname); break; - case FT_NORECURSE: - printf(_("Recursion turned off. Directory not entered. %s\n"), ff->fname); - break; - case FT_NOFSCHG: - printf(_("Skip: File system change prohibited. Directory not entered. %s\n"), ff->fname); - break; case FT_NOOPEN: printf(_("Err: Could not open directory %s: %s\n"), ff->fname, strerror(errno)); break; @@ -256,14 +260,14 @@ static int print_file(FF_PKT *ff, void *pkt) char attr[200]; encode_attribsEx(NULL, attr, ff); if (*attr != 0) { - printf("AttrEx=%s\n", attr); + printf("AttrEx=%s\n", attr); } // set_attribsEx(NULL, ff->fname, NULL, NULL, ff->type, attr); } return 1; } -static void count_files(FF_PKT *ar) +static void count_files(FF_PKT *ar) { int fnl, pnl; char *l, *p; @@ -272,7 +276,7 @@ static void count_files(FF_PKT *ar) num_files++; - /* Find path without the filename. + /* Find path without the filename. * I.e. everything after the last / is a "filename". * OK, maybe it is a directory name, but we treat it like * a filename. If we don't find a / then the whole name @@ -290,7 +294,7 @@ static void count_files(FF_PKT *ar) } /* If filename doesn't exist (i.e. root directory), we - * simply create a blank name consisting of a single + * simply create a blank name consisting of a single * space. This makes handling zero length filenames * easier. */ @@ -311,7 +315,7 @@ static void count_files(FF_PKT *ar) file[1] = 0; } - pnl = l - ar->fname; + pnl = l - ar->fname; if (pnl > max_path_len) { max_path_len = pnl; }