2 * Test program for listing files during regression testing
5 Copyright (C) 2000-2005 Kern Sibbald
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 version 2 as amended with additional clauses defined in the
10 file LICENSE in the main source directory.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 the file LICENSE for additional details.
20 #include "findlib/find.h"
23 int generate_daemon_event(JCR *jcr, const char *event) { return 1; }
24 int generate_job_event(JCR *jcr, const char *event) { return 1; }
27 /* Global variables */
33 static int print_file(FF_PKT *ff, void *pkt, bool);
34 static void print_ls_output(char *fname, char *link, int type, struct stat *statp);
40 "Usage: testls [-d debug_level] [-] [pattern1 ...]\n"
41 " -a print extended attributes (Win32 debug)\n"
42 " -dnn set debug level to nn\n"
43 " -e specify file of exclude patterns\n"
44 " -i specify file of include patterns\n"
45 " - read pattern(s) from stdin\n"
46 " -? print this message.\n"
48 "Patterns are file inclusion -- normally directories.\n"
49 "Debug level >= 1 prints each file found.\n"
50 "Debug level >= 10 prints path/file for catalog.\n"
51 "Errors always printed.\n"
52 "Files/paths truncated is number with len > 255.\n"
53 "Truncation is only in catalog.\n"
61 main (int argc, char *const *argv)
65 int i, ch, hard_links;
70 setlocale(LC_ALL, "");
71 bindtextdomain("bacula", LOCALEDIR);
74 while ((ch = getopt(argc, argv, "ad:e:i:?")) != -1) {
76 case 'a': /* print extended attributes *debug* */
80 case 'd': /* set debug level */
81 debug_level = atoi(optarg);
82 if (debug_level <= 0) {
87 case 'e': /* exclude patterns */
91 case 'i': /* include patterns */
104 jcr = new_jcr(sizeof(JCR), NULL);
106 ff = init_find_files();
107 if (argc == 0 && !inc) {
108 add_fname_to_include_list(ff, 0, "/"); /* default to / */
110 for (i=0; i < argc; i++) {
111 if (strcmp(argv[i], "-") == 0) {
112 while (fgets(name, sizeof(name)-1, stdin)) {
113 strip_trailing_junk(name);
114 add_fname_to_include_list(ff, 0, name);
118 add_fname_to_include_list(ff, 0, argv[i]);
122 fd = fopen(inc, "rb");
124 printf(_("Could not open include file: %s\n"), inc);
127 while (fgets(name, sizeof(name)-1, fd)) {
128 strip_trailing_junk(name);
129 add_fname_to_include_list(ff, 0, name);
135 fd = fopen(exc, "rb");
137 printf(_("Could not open exclude file: %s\n"), exc);
140 while (fgets(name, sizeof(name)-1, fd)) {
141 strip_trailing_junk(name);
142 add_fname_to_exclude_list(ff, name);
146 match_files(jcr, ff, print_file, NULL);
147 term_include_exclude_files(ff);
148 hard_links = term_find_files(ff);
151 term_last_jobs_list(); /* free jcr chain */
157 static int print_file(FF_PKT *ff, void *pkt, bool top_level)
167 print_ls_output(ff->fname, ff->link, ff->type, &ff->statp);
172 printf(_("Err: Could not access %s: %s\n"), ff->fname, strerror(errno));
175 printf(_("Err: Could not follow ff->link %s: %s\n"), ff->fname, strerror(errno));
178 printf(_("Err: Could not stat %s: %s\n"), ff->fname, strerror(errno));
181 printf(_("Skip: File not saved. No change. %s\n"), ff->fname);
184 printf(_("Err: Attempt to backup archive. Not saved. %s\n"), ff->fname);
187 printf(_("Recursion turned off. Directory not entered. %s\n"), ff->fname);
190 printf(_("Skip: File system change prohibited. Directory not entered. %s\n"), ff->fname);
193 printf(_("Err: Could not open directory %s: %s\n"), ff->fname, strerror(errno));
196 printf(_("Err: Unknown file ff->type %d: %s\n"), ff->type, ff->fname);
202 static void print_ls_output(char *fname, char *link, int type, struct stat *statp)
209 if (type == FT_LNK) {
211 statp->st_mode |= 0777;
213 p = encode_mode(statp->st_mode, buf);
214 n = sprintf(p, " %2d ", (uint32_t)statp->st_nlink);
216 n = sprintf(p, "%-4d %-4d", (int)statp->st_uid, (int)statp->st_gid);
218 n = sprintf(p, "%7.7s ", edit_uint64(statp->st_size, ec1));
220 if (S_ISCHR(statp->st_mode) || S_ISBLK(statp->st_mode)) {
221 n = sprintf(p, "%4x ", (int)statp->st_rdev);
226 p = encode_time(statp->st_mtime, p);
229 for (f=fname; *f && (p-buf) < (int)sizeof(buf); )
231 if (type == FT_LNK) {
236 for (f=link; *f && (p-buf) < (int)sizeof(buf); )
244 bool python_set_prog(JCR*, char const*) { return false; }