2 Bacula® - The Network Backup Solution
4 Copyright (C) 2000-2014 Free Software Foundation Europe e.V.
6 The main author of Bacula is Kern Sibbald, with contributions from many
7 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 Bacula® is a registered trademark of Kern Sibbald.
17 * Test program for listing files during regression testing
18 * Links have their permissions and time bashed since they cannot
26 #include "findlib/find.h"
29 int generate_daemon_event(JCR *jcr, const char *event) { return 1; }
30 int generate_job_event(JCR *jcr, const char *event) { return 1; }
31 void generate_plugin_event(JCR *jcr, bEventType eventType, void *value) { }
34 /* Global variables */
38 static int num_files = 0;
40 static int print_file(JCR *jcr, FF_PKT *ff, bool);
41 static void print_ls_output(char *fname, char *link, int type, struct stat *statp);
42 static int count_files(JCR *jcr, FF_PKT *ff, bool top_level);
48 "Usage: testls [-d debug_level] [-] [pattern1 ...]\n"
49 " -a print extended attributes (Win32 debug)\n"
50 " -d <nn> set debug level to <nn>\n"
51 " -dt print timestamp in debug output\n"
52 " -e specify file of exclude patterns\n"
53 " -i specify file of include patterns\n"
54 " -q quiet, don't print filenames (debug)\n"
55 " - read pattern(s) from stdin\n"
56 " -? print this message.\n"
58 "Patterns are file inclusion -- normally directories.\n"
59 "Debug level >= 1 prints each file found.\n"
60 "Debug level >= 10 prints path/file for catalog.\n"
61 "Errors always printed.\n"
62 "Files/paths truncated is number with len > 255.\n"
63 "Truncation is only in catalog.\n"
70 int main(int argc, char *const *argv)
80 setlocale(LC_ALL, "");
81 bindtextdomain("bacula", LOCALEDIR);
85 while ((ch = getopt(argc, argv, "ad:e:i:q?")) != -1) {
87 case 'a': /* print extended attributes *debug* */
91 case 'd': /* set debug level */
95 debug_level = atoi(optarg);
96 if (debug_level <= 0) {
102 case 'e': /* exclude patterns */
106 case 'i': /* include patterns */
123 jcr = new_jcr(sizeof(JCR), NULL);
125 ff = init_find_files();
126 if (argc == 0 && !inc) {
127 add_fname_to_include_list(ff, 0, "/"); /* default to / */
129 for (i=0; i < argc; i++) {
130 if (strcmp(argv[i], "-") == 0) {
131 while (fgets(name, sizeof(name)-1, stdin)) {
132 strip_trailing_junk(name);
133 add_fname_to_include_list(ff, 0, name);
137 add_fname_to_include_list(ff, 0, argv[i]);
141 fd = fopen(inc, "rb");
143 printf(_("Could not open include file: %s\n"), inc);
146 while (fgets(name, sizeof(name)-1, fd)) {
147 strip_trailing_junk(name);
148 add_fname_to_include_list(ff, 0, name);
154 fd = fopen(exc, "rb");
156 printf(_("Could not open exclude file: %s\n"), exc);
159 while (fgets(name, sizeof(name)-1, fd)) {
160 strip_trailing_junk(name);
161 add_fname_to_exclude_list(ff, name);
166 match_files(jcr, ff, count_files);
168 match_files(jcr, ff, print_file);
170 printf(_("Files seen = %d\n"), num_files);
171 term_include_exclude_files(ff);
175 term_last_jobs_list(); /* free jcr chain */
182 static int count_files(JCR *jcr, FF_PKT *ff, bool top_level)
188 static int print_file(JCR *jcr, FF_PKT *ff, bool top_level)
198 print_ls_output(ff->fname, ff->link, ff->type, &ff->statp);
203 printf(_("Err: Could not access %s: %s\n"), ff->fname, strerror(errno));
206 printf(_("Err: Could not follow ff->link %s: %s\n"), ff->fname, strerror(errno));
209 printf(_("Err: Could not stat %s: %s\n"), ff->fname, strerror(errno));
212 printf(_("Skip: File not saved. No change. %s\n"), ff->fname);
215 printf(_("Err: Attempt to backup archive. Not saved. %s\n"), ff->fname);
218 printf(_("Recursion turned off. Directory not entered. %s\n"), ff->fname);
221 printf(_("Skip: File system change prohibited. Directory not entered. %s\n"), ff->fname);
224 printf(_("Err: Could not open directory %s: %s\n"), ff->fname, strerror(errno));
227 printf(_("Err: Unknown file ff->type %d: %s\n"), ff->type, ff->fname);
234 static void print_ls_output(char *fname, char *link, int type, struct stat *statp)
241 if (type == FT_LNK) {
243 statp->st_mode |= 0777;
245 p = encode_mode(statp->st_mode, buf);
246 n = sprintf(p, " %2d ", (uint32_t)statp->st_nlink);
248 n = sprintf(p, "%-4d %-4d", (int)statp->st_uid, (int)statp->st_gid);
250 n = sprintf(p, "%10.10s ", edit_uint64(statp->st_size, ec1));
252 if (S_ISCHR(statp->st_mode) || S_ISBLK(statp->st_mode)) {
253 n = sprintf(p, "%4x ", (int)statp->st_rdev);
258 p = encode_time(statp->st_mtime, p);
261 for (f=fname; *f && (p-buf) < (int)sizeof(buf); )
263 if (type == FT_LNK) {
268 for (f=link; *f && (p-buf) < (int)sizeof(buf); )
276 bool python_set_prog(JCR*, char const*) { return false; }