2 Bacula(R) - The Network Backup Solution
4 Copyright (C) 2000-2015 Kern Sibbald
5 Copyright (C) 2000-2014 Free Software Foundation Europe e.V.
7 The original author of Bacula is Kern Sibbald, with contributions
8 from many others, a complete list can be found in the file AUTHORS.
10 You may use this file and others of this release according to the
11 license defined in the LICENSE file, which includes the Affero General
12 Public License, v3.0 ("AGPLv3") and some additional permissions and
13 terms pursuant to its AGPLv3 Section 7.
15 This notice must be preserved when any source code is
16 conveyed and/or propagated.
18 Bacula(R) is a registered trademark of Kern Sibbald.
21 * Test program for listing files during regression testing
22 * Links have their permissions and time bashed since they cannot
30 #include "findlib/find.h"
33 int generate_job_event(JCR *jcr, const char *event) { return 1; }
34 void generate_plugin_event(JCR *jcr, bEventType eventType, void *value) { }
37 /* Global variables */
41 static int num_files = 0;
43 static int print_file(JCR *jcr, FF_PKT *ff, bool);
44 static void print_ls_output(char *fname, char *link, int type, struct stat *statp);
45 static int count_files(JCR *jcr, FF_PKT *ff, bool top_level);
51 "Usage: testls [-d debug_level] [-] [pattern1 ...]\n"
52 " -a print extended attributes (Win32 debug)\n"
53 " -d <nn> set debug level to <nn>\n"
54 " -dt print timestamp in debug output\n"
55 " -e specify file of exclude patterns\n"
56 " -i specify file of include patterns\n"
57 " -q quiet, don't print filenames (debug)\n"
58 " - read pattern(s) from stdin\n"
59 " -? print this message.\n"
61 "Patterns are file inclusion -- normally directories.\n"
62 "Debug level >= 1 prints each file found.\n"
63 "Debug level >= 10 prints path/file for catalog.\n"
64 "Errors always printed.\n"
65 "Files/paths truncated is number with len > 255.\n"
66 "Truncation is only in catalog.\n"
73 int main(int argc, char *const *argv)
83 setlocale(LC_ALL, "");
84 bindtextdomain("bacula", LOCALEDIR);
88 while ((ch = getopt(argc, argv, "ad:e:i:q?")) != -1) {
90 case 'a': /* print extended attributes *debug* */
94 case 'd': /* set debug level */
98 debug_level = atoi(optarg);
99 if (debug_level <= 0) {
105 case 'e': /* exclude patterns */
109 case 'i': /* include patterns */
126 jcr = new_jcr(sizeof(JCR), NULL);
128 ff = init_find_files();
129 if (argc == 0 && !inc) {
130 add_fname_to_include_list(ff, 0, "/"); /* default to / */
132 for (i=0; i < argc; i++) {
133 if (strcmp(argv[i], "-") == 0) {
134 while (fgets(name, sizeof(name)-1, stdin)) {
135 strip_trailing_junk(name);
136 add_fname_to_include_list(ff, 0, name);
140 add_fname_to_include_list(ff, 0, argv[i]);
144 fd = fopen(inc, "rb");
146 printf(_("Could not open include file: %s\n"), inc);
149 while (fgets(name, sizeof(name)-1, fd)) {
150 strip_trailing_junk(name);
151 add_fname_to_include_list(ff, 0, name);
157 fd = fopen(exc, "rb");
159 printf(_("Could not open exclude file: %s\n"), exc);
162 while (fgets(name, sizeof(name)-1, fd)) {
163 strip_trailing_junk(name);
164 add_fname_to_exclude_list(ff, name);
169 match_files(jcr, ff, count_files);
171 match_files(jcr, ff, print_file);
173 printf(_("Files seen = %d\n"), num_files);
174 term_include_exclude_files(ff);
178 term_last_jobs_list(); /* free jcr chain */
185 static int count_files(JCR *jcr, FF_PKT *ff, bool top_level)
191 static int print_file(JCR *jcr, FF_PKT *ff, bool top_level)
201 print_ls_output(ff->fname, ff->link, ff->type, &ff->statp);
206 printf(_("Err: Could not access %s: %s\n"), ff->fname, strerror(errno));
209 printf(_("Err: Could not follow ff->link %s: %s\n"), ff->fname, strerror(errno));
212 printf(_("Err: Could not stat %s: %s\n"), ff->fname, strerror(errno));
215 printf(_("Skip: File not saved. No change. %s\n"), ff->fname);
218 printf(_("Err: Attempt to backup archive. Not saved. %s\n"), ff->fname);
221 printf(_("Recursion turned off. Directory not entered. %s\n"), ff->fname);
224 printf(_("Skip: File system change prohibited. Directory not entered. %s\n"), ff->fname);
227 printf(_("Err: Could not open directory %s: %s\n"), ff->fname, strerror(errno));
230 printf(_("Err: Unknown file ff->type %d: %s\n"), ff->type, ff->fname);
237 static void print_ls_output(char *fname, char *link, int type, struct stat *statp)
244 if (type == FT_LNK) {
246 statp->st_mode |= 0777;
248 p = encode_mode(statp->st_mode, buf);
249 n = sprintf(p, " %2d ", (uint32_t)statp->st_nlink);
251 n = sprintf(p, "%-4d %-4d", (int)statp->st_uid, (int)statp->st_gid);
253 n = sprintf(p, "%10.10s ", edit_uint64(statp->st_size, ec1));
255 if (S_ISCHR(statp->st_mode) || S_ISBLK(statp->st_mode)) {
256 n = sprintf(p, "%4x ", (int)statp->st_rdev);
261 p = encode_time(statp->st_mtime, p);
264 for (f=fname; *f && (p-buf) < (int)sizeof(buf); )
266 if (type == FT_LNK) {
271 for (f=link; *f && (p-buf) < (int)sizeof(buf); )
279 bool python_set_prog(JCR*, char const*) { return false; }