4 #include <rpmio_internal.h>
6 #include <rpmmessages.h>
12 static int _fts_debug = 0;
14 #define FTPPATH "ftp://porkchop/mnt/redhat/beehive/comps/dist/7.2-rpm"
15 #define DIRPATH "/mnt/redhat/beehive/comps/dist/7.2-rpm"
16 static char * dirpath = DIRPATH;
17 static char * ftppath = FTPPATH;
20 static int nfiles = 0;
22 static int indent = 2;
24 static const char * ftsInfoStrings[] = {
42 static const char * ftsInfoStr(int fts_info) {
43 if (!(fts_info >= 1 && fts_info <= 14))
45 return ftsInfoStrings[ fts_info ];
48 static int ftsPrint(FTS * ftsp, FTSENT * fts)
52 fprintf(stderr, "FTS_%s\t%*s %s\n", ftsInfoStr(fts->fts_info),
53 indent * (fts->fts_level < 0 ? 0 : fts->fts_level), "",
56 switch (fts->fts_info) {
57 case FTS_D: /* preorder directory */
60 case FTS_DP: /* postorder directory */
62 case FTS_F: /* regular file */
65 case FTS_NS: /* stat(2) failed */
66 case FTS_DNR: /* unreadable directory */
67 case FTS_ERR: /* error; errno is set */
69 case FTS_DC: /* directory that causes cycles */
70 case FTS_DEFAULT: /* none of the above */
71 case FTS_DOT: /* dot or dot-dot */
72 case FTS_INIT: /* initialized only */
73 case FTS_NSOK: /* no stat(2) requested */
74 case FTS_SL: /* symbolic link */
75 case FTS_SLNONE: /* symbolic link without target */
76 case FTS_W: /* whiteout object */
85 static int ftsOpts = 0;
87 static void ftsWalk(const char * path)
89 const char * ftsSet[2];
99 ftsp = Fts_open((char *const *)ftsSet, ftsOpts, NULL);
100 while((fts = Fts_read(ftsp)) != NULL)
101 xx = ftsPrint(ftsp, fts);
102 xx = Fts_close(ftsp);
103 fprintf(stderr, "===== (%d/%d) dirs/files in %s\n", ndirs, nfiles, path);
107 static struct poptOption optionsTable[] = {
108 { "ftsdebug", 'd', POPT_ARG_VAL, &_fts_debug, -1, NULL, NULL },
110 { "comfollow", '\0', POPT_BIT_SET, &ftsOpts, FTS_COMFOLLOW,
111 N_("follow command line symlinks"), NULL },
112 { "logical", '\0', POPT_BIT_SET, &ftsOpts, FTS_LOGICAL,
113 N_("logical walk"), NULL },
114 { "nochdir", '\0', POPT_BIT_SET, &ftsOpts, FTS_NOCHDIR,
115 N_("don't change directories"), NULL },
116 { "nostat", '\0', POPT_BIT_SET, &ftsOpts, FTS_NOSTAT,
117 N_("don't get stat info"), NULL },
118 { "physical", '\0', POPT_BIT_SET, &ftsOpts, FTS_PHYSICAL,
119 N_("physical walk"), NULL },
120 { "seedot", '\0', POPT_BIT_SET, &ftsOpts, FTS_SEEDOT,
121 N_("return dot and dot-dot"), NULL },
122 { "xdev", '\0', POPT_BIT_SET, &ftsOpts, FTS_XDEV,
123 N_("don't cross devices"), NULL },
124 { "whiteout", '\0', POPT_BIT_SET, &ftsOpts, FTS_WHITEOUT,
125 N_("return whiteout information"), NULL },
127 { "ftpdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_ftp_debug, -1,
128 N_("debug protocol data stream"), NULL},
129 { "rpmiodebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmio_debug, -1,
130 N_("debug rpmio I/O"), NULL},
131 { "urldebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_url_debug, -1,
132 N_("debug URL cache handling"), NULL},
133 { "verbose", 'v', 0, 0, 'v', NULL, NULL },
139 main(int argc, const char *argv[])
141 poptContext optCon = poptGetContext(argv[0], argc, argv, optionsTable, 0);
144 while ((rc = poptGetNextOpt(optCon)) > 0) {
147 rpmIncreaseVerbosity();
148 /*@switchbreak@*/ break;
150 /*@switchbreak@*/ break;
155 ftsOpts = (FTS_COMFOLLOW | FTS_LOGICAL | FTS_NOSTAT);