2 Bacula(R) - The Network Backup Solution
4 Copyright (C) 2000-2016 Kern Sibbald
6 The original author of Bacula is Kern Sibbald, with contributions
7 from many others, a complete list can be found in the file AUTHORS.
9 You may use this file and others of this release according to the
10 license defined in the LICENSE file, which includes the Affero General
11 Public License, v3.0 ("AGPLv3") and some additional permissions and
12 terms pursuant to its AGPLv3 Section 7.
14 This notice must be preserved when any source code is
15 conveyed and/or propagated.
17 Bacula(R) is a registered trademark of Kern Sibbald.
20 * Test program for listing files during regression testing
21 * Links have their permissions and time bashed since they cannot
29 #include "findlib/find.h"
32 int generate_job_event(JCR *jcr, const char *event) { return 1; }
33 void generate_plugin_event(JCR *jcr, bEventType eventType, void *value) { }
36 /* Global variables */
40 static int num_files = 0;
42 static int print_file(JCR *jcr, FF_PKT *ff, bool);
43 static void print_ls_output(char *fname, char *link, int type, struct stat *statp);
44 static int count_files(JCR *jcr, FF_PKT *ff, bool top_level);
50 "Usage: testls [-d debug_level] [-] [pattern1 ...]\n"
51 " -a print extended attributes (Win32 debug)\n"
52 " -d <nn> set debug level to <nn>\n"
53 " -dt print timestamp in debug output\n"
54 " -e specify file of exclude patterns\n"
55 " -i specify file of include patterns\n"
56 " -q quiet, don't print filenames (debug)\n"
57 " - read pattern(s) from stdin\n"
58 " -? print this message.\n"
60 "Patterns are file inclusion -- normally directories.\n"
61 "Debug level >= 1 prints each file found.\n"
62 "Debug level >= 10 prints path/file for catalog.\n"
63 "Errors always printed.\n"
64 "Files/paths truncated is number with len > 255.\n"
65 "Truncation is only in catalog.\n"
72 int main(int argc, char *const *argv)
82 setlocale(LC_ALL, "");
83 bindtextdomain("bacula", LOCALEDIR);
87 while ((ch = getopt(argc, argv, "ad:e:i:q?")) != -1) {
89 case 'a': /* print extended attributes *debug* */
93 case 'd': /* set debug level */
97 debug_level = atoi(optarg);
98 if (debug_level <= 0) {
104 case 'e': /* exclude patterns */
108 case 'i': /* include patterns */
125 jcr = new_jcr(sizeof(JCR), NULL);
127 ff = init_find_files();
128 if (argc == 0 && !inc) {
129 add_fname_to_include_list(ff, 0, "/"); /* default to / */
131 for (i=0; i < argc; i++) {
132 if (strcmp(argv[i], "-") == 0) {
133 while (fgets(name, sizeof(name)-1, stdin)) {
134 strip_trailing_junk(name);
135 add_fname_to_include_list(ff, 0, name);
139 add_fname_to_include_list(ff, 0, argv[i]);
143 fd = fopen(inc, "rb");
145 printf(_("Could not open include file: %s\n"), inc);
148 while (fgets(name, sizeof(name)-1, fd)) {
149 strip_trailing_junk(name);
150 add_fname_to_include_list(ff, 0, name);
156 fd = fopen(exc, "rb");
158 printf(_("Could not open exclude file: %s\n"), exc);
161 while (fgets(name, sizeof(name)-1, fd)) {
162 strip_trailing_junk(name);
163 add_fname_to_exclude_list(ff, name);
168 match_files(jcr, ff, count_files);
170 match_files(jcr, ff, print_file);
172 printf(_("Files seen = %d\n"), num_files);
173 term_include_exclude_files(ff);
177 term_last_jobs_list(); /* free jcr chain */
184 static int count_files(JCR *jcr, FF_PKT *ff, bool top_level)
190 static int print_file(JCR *jcr, FF_PKT *ff, bool top_level)
200 print_ls_output(ff->fname, ff->link, ff->type, &ff->statp);
205 printf(_("Err: Could not access %s: %s\n"), ff->fname, strerror(errno));
208 printf(_("Err: Could not follow ff->link %s: %s\n"), ff->fname, strerror(errno));
211 printf(_("Err: Could not stat %s: %s\n"), ff->fname, strerror(errno));
214 printf(_("Skip: File not saved. No change. %s\n"), ff->fname);
217 printf(_("Err: Attempt to backup archive. Not saved. %s\n"), ff->fname);
220 printf(_("Recursion turned off. Directory not entered. %s\n"), ff->fname);
223 printf(_("Skip: File system change prohibited. Directory not entered. %s\n"), ff->fname);
226 printf(_("Err: Could not open directory %s: %s\n"), ff->fname, strerror(errno));
229 printf(_("Err: Unknown file ff->type %d: %s\n"), ff->type, ff->fname);
236 static void print_ls_output(char *fname, char *link, int type, struct stat *statp)
243 if (type == FT_LNK) {
245 statp->st_mode |= 0777;
247 p = encode_mode(statp->st_mode, buf);
248 n = sprintf(p, " %2d ", (uint32_t)statp->st_nlink);
250 n = sprintf(p, "%-4d %-4d", (int)statp->st_uid, (int)statp->st_gid);
252 n = sprintf(p, "%10.10s ", edit_uint64(statp->st_size, ec1));
254 if (S_ISCHR(statp->st_mode) || S_ISBLK(statp->st_mode)) {
255 n = sprintf(p, "%4x ", (int)statp->st_rdev);
260 p = encode_time(statp->st_mtime, p);
263 for (f=fname; *f && (p-buf) < (int)sizeof(buf); )
265 if (type == FT_LNK) {
270 for (f=link; *f && (p-buf) < (int)sizeof(buf); )
278 bool python_set_prog(JCR*, char const*) { return false; }