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"
22 #if defined(HAVE_CYGWIN) || defined(HAVE_WIN32)
29 int generate_daemon_event(JCR *jcr, const char *event) { return 1; }
30 int generate_job_event(JCR *jcr, const char *event) { return 1; }
33 /* Global variables */
39 static int print_file(FF_PKT *ff, void *pkt, bool);
40 static void print_ls_output(char *fname, char *link, int type, struct stat *statp);
46 "Usage: testls [-d debug_level] [-] [pattern1 ...]\n"
47 " -a print extended attributes (Win32 debug)\n"
48 " -dnn set debug level to nn\n"
49 " -e specify file of exclude patterns\n"
50 " -i specify file of include patterns\n"
51 " - read pattern(s) from stdin\n"
52 " -? print this message.\n"
54 "Patterns are file inclusion -- normally directories.\n"
55 "Debug level >= 1 prints each file found.\n"
56 "Debug level >= 10 prints path/file for catalog.\n"
57 "Errors always printed.\n"
58 "Files/paths truncated is number with len > 255.\n"
59 "Truncation is only in catalog.\n"
67 main (int argc, char *const *argv)
71 int i, ch, hard_links;
76 while ((ch = getopt(argc, argv, "ad:e:i:?")) != -1) {
78 case 'a': /* print extended attributes *debug* */
82 case 'd': /* set debug level */
83 debug_level = atoi(optarg);
84 if (debug_level <= 0) {
89 case 'e': /* exclude patterns */
93 case 'i': /* include patterns */
106 jcr = new_jcr(sizeof(JCR), NULL);
108 ff = init_find_files();
109 if (argc == 0 && !inc) {
110 add_fname_to_include_list(ff, 0, "/"); /* default to / */
112 for (i=0; i < argc; i++) {
113 if (strcmp(argv[i], "-") == 0) {
114 while (fgets(name, sizeof(name)-1, stdin)) {
115 strip_trailing_junk(name);
116 add_fname_to_include_list(ff, 0, name);
120 add_fname_to_include_list(ff, 0, argv[i]);
124 fd = fopen(inc, "r");
126 printf("Could not open include file: %s\n", inc);
129 while (fgets(name, sizeof(name)-1, fd)) {
130 strip_trailing_junk(name);
131 add_fname_to_include_list(ff, 0, name);
137 fd = fopen(exc, "r");
139 printf("Could not open exclude file: %s\n", exc);
142 while (fgets(name, sizeof(name)-1, fd)) {
143 strip_trailing_junk(name);
144 add_fname_to_exclude_list(ff, name);
148 match_files(jcr, ff, print_file, NULL);
149 term_include_exclude_files(ff);
150 hard_links = term_find_files(ff);
153 term_last_jobs_list(); /* free jcr chain */
159 static int print_file(FF_PKT *ff, void *pkt, bool top_level)
169 print_ls_output(ff->fname, ff->link, ff->type, &ff->statp);
174 printf(_("Err: Could not access %s: %s\n"), ff->fname, strerror(errno));
177 printf(_("Err: Could not follow ff->link %s: %s\n"), ff->fname, strerror(errno));
180 printf(_("Err: Could not stat %s: %s\n"), ff->fname, strerror(errno));
183 printf(_("Skip: File not saved. No change. %s\n"), ff->fname);
186 printf(_("Err: Attempt to backup archive. Not saved. %s\n"), ff->fname);
189 printf(_("Recursion turned off. Directory not entered. %s\n"), ff->fname);
192 printf(_("Skip: File system change prohibited. Directory not entered. %s\n"), ff->fname);
195 printf(_("Err: Could not open directory %s: %s\n"), ff->fname, strerror(errno));
198 printf(_("Err: Unknown file ff->type %d: %s\n"), ff->type, ff->fname);
204 static void print_ls_output(char *fname, char *link, int type, struct stat *statp)
211 if (type == FT_LNK) {
213 statp->st_mode |= 0777;
215 p = encode_mode(statp->st_mode, buf);
216 n = sprintf(p, " %2d ", (uint32_t)statp->st_nlink);
218 n = sprintf(p, "%-4d %-4d", (int)statp->st_uid, (int)statp->st_gid);
220 n = sprintf(p, "%7.7s ", edit_uint64(statp->st_size, ec1));
222 if (S_ISCHR(statp->st_mode) || S_ISBLK(statp->st_mode)) {
223 n = sprintf(p, "%4x ", (int)statp->st_rdev);
228 p = encode_time(statp->st_mtime, p);
231 for (f=fname; *f && (p-buf) < (int)sizeof(buf); )
233 if (type == FT_LNK) {
238 for (f=link; *f && (p-buf) < (int)sizeof(buf); )
246 bool python_set_prog(JCR*, char const*) { return false; }