1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
|
#include "system.h"
#include "rpmio/fts.h"
#include "rpmio/rpmio_internal.h"
#include <rpmmacro.h>
#include <rpmlog.h>
#include <popt.h>
#include "debug.h"
static int _fts_debug = 0;
#if 0
#define HTTPSPATH "https://localhost/rawhide/test/"
#define HTTPPATH "http://localhost/rawhide/test/"
#else
#define HTTPSPATH "https://localhost/rawhide/"
#define HTTPPATH "http://localhost/rawhide/"
#endif
#define FTPPATH "ftp://localhost/pub/rawhide/packages/test"
#define DIRPATH "/var/ftp/pub/rawhide/packages/test"
static char * httpspath = HTTPSPATH;
static char * httppath = HTTPPATH;
static char * ftppath = FTPPATH;
static char * dirpath = DIRPATH;
static int ndirs = 0;
static int nfiles = 0;
static int indent = 2;
static const char * ftsInfoStrings[] = {
"UNKNOWN",
"D",
"DC",
"DEFAULT",
"DNR",
"DOT",
"DP",
"ERR",
"F",
"INIT",
"NS",
"NSOK",
"SL",
"SLNONE",
"W",
};
static const char * ftsInfoStr(int fts_info) {
if (!(fts_info >= 1 && fts_info <= 14))
fts_info = 0;
return ftsInfoStrings[ fts_info ];
}
static int ftsPrint(FTS * ftsp, FTSENT * fts)
{
if (_fts_debug)
fprintf(stderr, "FTS_%s\t%*s %s\n", ftsInfoStr(fts->fts_info),
indent * (fts->fts_level < 0 ? 0 : fts->fts_level), "",
fts->fts_name);
switch (fts->fts_info) {
case FTS_D: /* preorder directory */
ndirs++;
break;
case FTS_DP: /* postorder directory */
break;
case FTS_F: /* regular file */
nfiles++;
break;
case FTS_NS: /* stat(2) failed */
case FTS_DNR: /* unreadable directory */
case FTS_ERR: /* error; errno is set */
break;
case FTS_DC: /* directory that causes cycles */
case FTS_DEFAULT: /* none of the above */
case FTS_DOT: /* dot or dot-dot */
case FTS_INIT: /* initialized only */
case FTS_NSOK: /* no stat(2) requested */
case FTS_SL: /* symbolic link */
case FTS_SLNONE: /* symbolic link without target */
case FTS_W: /* whiteout object */
default:
break;
}
return 0;
}
static int ftsOpts = 0;
static void ftsWalk(const char * path)
{
const char * ftsSet[2];
FTS * ftsp;
FTSENT * fts;
int xx;
ftsSet[0] = path;
ftsSet[1] = NULL;
ndirs = nfiles = 0;
ftsp = Fts_open((char *const *)ftsSet, ftsOpts, NULL);
while((fts = Fts_read(ftsp)) != NULL)
xx = ftsPrint(ftsp, fts);
xx = Fts_close(ftsp);
fprintf(stderr, "===== (%d/%d) dirs/files in %s\n", ndirs, nfiles, path);
}
static struct poptOption optionsTable[] = {
{ "ftsdebug", 'd', POPT_ARG_VAL, &_fts_debug, -1, NULL, NULL },
{ "comfollow", '\0', POPT_BIT_SET, &ftsOpts, FTS_COMFOLLOW,
N_("follow command line symlinks"), NULL },
{ "logical", '\0', POPT_BIT_SET, &ftsOpts, FTS_LOGICAL,
N_("logical walk"), NULL },
{ "nochdir", '\0', POPT_BIT_SET, &ftsOpts, FTS_NOCHDIR,
N_("don't change directories"), NULL },
{ "nostat", '\0', POPT_BIT_SET, &ftsOpts, FTS_NOSTAT,
N_("don't get stat info"), NULL },
{ "physical", '\0', POPT_BIT_SET, &ftsOpts, FTS_PHYSICAL,
N_("physical walk"), NULL },
{ "seedot", '\0', POPT_BIT_SET, &ftsOpts, FTS_SEEDOT,
N_("return dot and dot-dot"), NULL },
{ "xdev", '\0', POPT_BIT_SET, &ftsOpts, FTS_XDEV,
N_("don't cross devices"), NULL },
{ "whiteout", '\0', POPT_BIT_SET, &ftsOpts, FTS_WHITEOUT,
N_("return whiteout information"), NULL },
{ "rpmiodebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmio_debug, -1,
N_("debug rpmio I/O"), NULL},
{ "urldebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_url_debug, -1,
N_("debug URL cache handling"), NULL},
{ "verbose", 'v', 0, 0, 'v', NULL, NULL },
POPT_AUTOHELP
POPT_TABLEEND
};
int
main(int argc, char *argv[])
{
poptContext optCon = poptGetContext(argv[0], argc, (const char **) argv, optionsTable, 0);
int rc;
while ((rc = poptGetNextOpt(optCon)) > 0) {
switch (rc) {
case 'v':
rpmIncreaseVerbosity();
break;
default:
break;
}
}
if (ftsOpts == 0)
ftsOpts = (FTS_COMFOLLOW | FTS_LOGICAL | FTS_NOSTAT);
#if 0
ftsWalk(dirpath);
ftsWalk(ftppath);
#endif
ftsWalk(httppath);
#if 0
ftsWalk(httpspath);
#endif
return 0;
}
|