2 Bacula® - The Network Backup Solution
4 Copyright (C) 2000-2010 Free Software Foundation Europe e.V.
6 The main author of Bacula is Kern Sibbald, with contributions from
7 many others, a complete list can be found in the file AUTHORS.
8 This program is Free Software; you can redistribute it and/or
9 modify it under the terms of version three of the GNU Affero General Public
10 License as published by the Free Software Foundation and included
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU Affero General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 Bacula® is a registered trademark of Kern Sibbald.
24 The licensor of Bacula is the Free Software Foundation Europe
25 (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
26 Switzerland, email:ftf@fsfeurope.org.
29 * Test program for listing files during regression testing
30 * Links have their permissions and time bashed since they cannot
38 #include "findlib/find.h"
41 int generate_daemon_event(JCR *jcr, const char *event) { return 1; }
42 int generate_job_event(JCR *jcr, const char *event) { return 1; }
43 void generate_plugin_event(JCR *jcr, bEventType eventType, void *value) { }
46 /* Global variables */
50 static int num_files = 0;
52 static int print_file(JCR *jcr, FF_PKT *ff, bool);
53 static void print_ls_output(char *fname, char *link, int type, struct stat *statp);
54 static int count_files(JCR *jcr, FF_PKT *ff, bool top_level);
60 "Usage: testls [-d debug_level] [-] [pattern1 ...]\n"
61 " -a print extended attributes (Win32 debug)\n"
62 " -d <nn> set debug level to <nn>\n"
63 " -dt print timestamp in debug output\n"
64 " -e specify file of exclude patterns\n"
65 " -i specify file of include patterns\n"
66 " -q quiet, don't print filenames (debug)\n"
67 " - read pattern(s) from stdin\n"
68 " -? print this message.\n"
70 "Patterns are file inclusion -- normally directories.\n"
71 "Debug level >= 1 prints each file found.\n"
72 "Debug level >= 10 prints path/file for catalog.\n"
73 "Errors always printed.\n"
74 "Files/paths truncated is number with len > 255.\n"
75 "Truncation is only in catalog.\n"
82 int main(int argc, char *const *argv)
87 int i, ch, hard_links;
92 setlocale(LC_ALL, "");
93 bindtextdomain("bacula", LOCALEDIR);
97 while ((ch = getopt(argc, argv, "ad:e:i:q?")) != -1) {
99 case 'a': /* print extended attributes *debug* */
103 case 'd': /* set debug level */
104 if (*optarg == 't') {
105 dbg_timestamp = true;
107 debug_level = atoi(optarg);
108 if (debug_level <= 0) {
114 case 'e': /* exclude patterns */
118 case 'i': /* include patterns */
135 jcr = new_jcr(sizeof(JCR), NULL);
137 ff = init_find_files();
138 if (argc == 0 && !inc) {
139 add_fname_to_include_list(ff, 0, "/"); /* default to / */
141 for (i=0; i < argc; i++) {
142 if (strcmp(argv[i], "-") == 0) {
143 while (fgets(name, sizeof(name)-1, stdin)) {
144 strip_trailing_junk(name);
145 add_fname_to_include_list(ff, 0, name);
149 add_fname_to_include_list(ff, 0, argv[i]);
153 fd = fopen(inc, "rb");
155 printf(_("Could not open include file: %s\n"), inc);
158 while (fgets(name, sizeof(name)-1, fd)) {
159 strip_trailing_junk(name);
160 add_fname_to_include_list(ff, 0, name);
166 fd = fopen(exc, "rb");
168 printf(_("Could not open exclude file: %s\n"), exc);
171 while (fgets(name, sizeof(name)-1, fd)) {
172 strip_trailing_junk(name);
173 add_fname_to_exclude_list(ff, name);
178 match_files(jcr, ff, count_files);
180 match_files(jcr, ff, print_file);
182 printf(_("Files seen = %d\n"), num_files);
183 term_include_exclude_files(ff);
184 hard_links = term_find_files(ff);
187 term_last_jobs_list(); /* free jcr chain */
194 static int count_files(JCR *jcr, FF_PKT *ff, bool top_level)
200 static int print_file(JCR *jcr, FF_PKT *ff, bool top_level)
210 print_ls_output(ff->fname, ff->link, ff->type, &ff->statp);
215 printf(_("Err: Could not access %s: %s\n"), ff->fname, strerror(errno));
218 printf(_("Err: Could not follow ff->link %s: %s\n"), ff->fname, strerror(errno));
221 printf(_("Err: Could not stat %s: %s\n"), ff->fname, strerror(errno));
224 printf(_("Skip: File not saved. No change. %s\n"), ff->fname);
227 printf(_("Err: Attempt to backup archive. Not saved. %s\n"), ff->fname);
230 printf(_("Recursion turned off. Directory not entered. %s\n"), ff->fname);
233 printf(_("Skip: File system change prohibited. Directory not entered. %s\n"), ff->fname);
236 printf(_("Err: Could not open directory %s: %s\n"), ff->fname, strerror(errno));
239 printf(_("Err: Unknown file ff->type %d: %s\n"), ff->type, ff->fname);
246 static void print_ls_output(char *fname, char *link, int type, struct stat *statp)
253 if (type == FT_LNK) {
255 statp->st_mode |= 0777;
257 p = encode_mode(statp->st_mode, buf);
258 n = sprintf(p, " %2d ", (uint32_t)statp->st_nlink);
260 n = sprintf(p, "%-4d %-4d", (int)statp->st_uid, (int)statp->st_gid);
262 n = sprintf(p, "%10.10s ", edit_uint64(statp->st_size, ec1));
264 if (S_ISCHR(statp->st_mode) || S_ISBLK(statp->st_mode)) {
265 n = sprintf(p, "%4x ", (int)statp->st_rdev);
270 p = encode_time(statp->st_mtime, p);
273 for (f=fname; *f && (p-buf) < (int)sizeof(buf); )
275 if (type == FT_LNK) {
280 for (f=link; *f && (p-buf) < (int)sizeof(buf); )
288 bool python_set_prog(JCR*, char const*) { return false; }