diff options
-rw-r--r-- | rpmio/.cvsignore | 5 | ||||
-rw-r--r-- | rpmio/Makefile.am | 8 | ||||
-rw-r--r-- | rpmio/rpmrpc.c | 28 | ||||
-rw-r--r-- | rpmio/tfts.c | 166 | ||||
-rw-r--r-- | tools/.cvsignore | 1 |
5 files changed, 204 insertions, 4 deletions
diff --git a/rpmio/.cvsignore b/rpmio/.cvsignore index eb7c93375..3ee447e40 100644 --- a/rpmio/.cvsignore +++ b/rpmio/.cvsignore @@ -7,5 +7,10 @@ Makefile.in *.la *.lo tdigest +tdir +tficl +tfts +tglob tkey +tring trpmio diff --git a/rpmio/Makefile.am b/rpmio/Makefile.am index 8ce483280..91a0a4734 100644 --- a/rpmio/Makefile.am +++ b/rpmio/Makefile.am @@ -2,9 +2,9 @@ AUTOMAKE_OPTIONS = 1.4 foreign -EXTRA_DIST = tdigest.c tdir.c tficl.c tglob.c tkey.c trpmio.c +EXTRA_DIST = tdigest.c tdir.c tficl.c tfts.c tglob.c tkey.c trpmio.c -EXTRA_PROGRAMS = tdigest tdir tglob tkey tring trpmio dumpasn1 +EXTRA_PROGRAMS = tdigest tdir tfts tglob tkey tring trpmio dumpasn1 INCLUDES = \ -I$(top_srcdir) \ @@ -58,6 +58,10 @@ tdir_SOURCES = tdir.c tdir_LDFLAGS = -all-static tdir_LDADD = librpmio.la $(top_builddir)/popt/libpopt.la +tfts_SOURCES = tfts.c +tfts_LDFLAGS = -all-static +tfts_LDADD = librpmio.la $(top_builddir)/popt/libpopt.la + tglob_SOURCES = tglob.c tglob_LDFLAGS = -all-static tglob_LDADD = librpmio.la $(top_builddir)/popt/libpopt.la diff --git a/rpmio/rpmrpc.c b/rpmio/rpmrpc.c index 1b36eb8ea..17483b50b 100644 --- a/rpmio/rpmrpc.c +++ b/rpmio/rpmrpc.c @@ -1006,6 +1006,23 @@ exit: } /*@=mods@*/ +static const char * statstr(struct stat * st) +{ + static char buf[1024]; +sprintf(buf, "*** dev %x ino %x mode %0o nlink %d uid %d gid %d rdev %x size %x\n", +(unsigned)st->st_dev, +(unsigned)st->st_ino, +st->st_mode, +st->st_nlink, +st->st_uid, +st->st_gid, +(unsigned)st->st_rdev, +(unsigned)st->st_size); + return buf; +} + +static int ftp_st_ino = 0x1000; + static int ftpStat(const char * path, /*@out@*/ struct stat *st) /*@globals fileSystem @*/ /*@modifies *st, fileSystem @*/ @@ -1013,7 +1030,10 @@ static int ftpStat(const char * path, /*@out@*/ struct stat *st) int rc; rc = ftpNLST(path, DO_FTP_STAT, st, NULL, 0); if (_ftp_debug) -fprintf(stderr, "*** ftpStat(%s) rc %d\n", path, rc); +fprintf(stderr, "*** ftpStat(%s) rc %d\n%s", path, rc, statstr(st)); + /* XXX fts(3) needs/uses st_ino, make something up for now. */ + if (st->st_ino == 0) + st->st_ino = ftp_st_ino++; return rc; } @@ -1024,7 +1044,11 @@ static int ftpLstat(const char * path, /*@out@*/ struct stat *st) int rc; rc = ftpNLST(path, DO_FTP_LSTAT, st, NULL, 0); if (_ftp_debug) -fprintf(stderr, "*** ftpLstat(%s) rc %d\n", path, rc); +fprintf(stderr, "*** ftpLstat(%s) rc %d\n%s\n", path, rc, statstr(st)); +st->st_ino = ftp_st_ino++; + /* XXX fts(3) needs/uses st_ino, make something up for now. */ + if (st->st_ino == 0) + st->st_ino = ftp_st_ino++; return rc; } diff --git a/rpmio/tfts.c b/rpmio/tfts.c new file mode 100644 index 000000000..affa21be3 --- /dev/null +++ b/rpmio/tfts.c @@ -0,0 +1,166 @@ +#include "system.h" +#include <fts.h> + +#include <rpmio_internal.h> +#include <rpmmacro.h> +#include <rpmmessages.h> +#include <popt.h> + +#include "debug.h" + +/*@unchecked@*/ +static int _fts_debug = 0; +/*@unchecked@*/ +extern int _ftp_debug; +/*@unchecked@*/ +extern int _rpmio_debug; + +#define FTPPATH "ftp://porkchop/mnt/redhat/beehive/comps/dist/7.2-rpm" +#define DIRPATH "/mnt/redhat/beehive/comps/dist/7.2-rpm" +static char * dirpath = DIRPATH; +static char * ftppath = FTPPATH; + +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; + int ftsOpts = (FTS_NOSTAT); + 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 }, + + { "ftpdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_ftp_debug, -1, + N_("debug protocol data stream"), 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, const char *argv[]) +{ + poptContext optCon = poptGetContext(argv[0], argc, argv, optionsTable, 0); + int rc; + + while ((rc = poptGetNextOpt(optCon)) > 0) { + switch (rc) { + case 'v': + rpmIncreaseVerbosity(); + /*@switchbreak@*/ break; + default: + /*@switchbreak@*/ break; + } + } + + if (ftsOpts == 0) + ftsOpts = (FTS_COMFOLLOW | FTS_LOGICAL | FTS_NOSTAT); + + ftsWalk(dirpath); + ftsWalk(ftppath); + + return 0; +} diff --git a/tools/.cvsignore b/tools/.cvsignore index 3e767c6be..88abdf774 100644 --- a/tools/.cvsignore +++ b/tools/.cvsignore @@ -12,3 +12,4 @@ rpminject rpmlead rpmsort rpmsignature +tpkgid |