rpmio/tfts.c

Go to the documentation of this file.
00001 #include "system.h"
00002 #include <fts.h>
00003 
00004 #include <rpmio_internal.h>
00005 #include <rpmmacro.h>
00006 #include <rpmmessages.h>
00007 #include <popt.h>
00008 
00009 #include "debug.h"
00010 
00011 /*@unchecked@*/
00012 static int _fts_debug = 0;
00013 
00014 #if 0
00015 #define HTTPSPATH       "https://localhost/rawhide/test/"
00016 #define HTTPPATH        "http://localhost/rawhide/test/"
00017 #else
00018 #define HTTPSPATH       "https://localhost/rawhide/"
00019 #define HTTPPATH        "http://localhost/rawhide/"
00020 #endif
00021 #define FTPPATH         "ftp://localhost/pub/rawhide/packages/test"
00022 #define DIRPATH         "/var/ftp/pub/rawhide/packages/test"
00023 static char * httpspath = HTTPSPATH;
00024 static char * httppath = HTTPPATH;
00025 static char * ftppath = FTPPATH;
00026 static char * dirpath = DIRPATH;
00027 
00028 static int ndirs = 0;
00029 static int nfiles = 0;
00030 
00031 static int indent = 2;
00032 
00033 static const char * ftsInfoStrings[] = {
00034     "UNKNOWN",
00035     "D",
00036     "DC",
00037     "DEFAULT",
00038     "DNR",
00039     "DOT",
00040     "DP",
00041     "ERR",
00042     "F",
00043     "INIT",
00044     "NS",
00045     "NSOK",
00046     "SL",
00047     "SLNONE",
00048     "W",
00049 };
00050 
00051 static const char * ftsInfoStr(int fts_info) {
00052     if (!(fts_info >= 1 && fts_info <= 14))
00053         fts_info = 0;
00054     return ftsInfoStrings[ fts_info ];
00055 }
00056 
00057 static int ftsPrint(FTS * ftsp, FTSENT * fts)
00058 {
00059 
00060     if (_fts_debug)
00061         fprintf(stderr, "FTS_%s\t%*s %s\n", ftsInfoStr(fts->fts_info),
00062                 indent * (fts->fts_level < 0 ? 0 : fts->fts_level), "",
00063                 fts->fts_name);
00064 
00065     switch (fts->fts_info) {
00066     case FTS_D:         /* preorder directory */
00067         ndirs++;
00068         break;
00069     case FTS_DP:        /* postorder directory */
00070         break;
00071     case FTS_F:         /* regular file */
00072         nfiles++;
00073         break;
00074     case FTS_NS:        /* stat(2) failed */
00075     case FTS_DNR:       /* unreadable directory */
00076     case FTS_ERR:       /* error; errno is set */
00077         break;
00078     case FTS_DC:        /* directory that causes cycles */
00079     case FTS_DEFAULT:   /* none of the above */
00080     case FTS_DOT:       /* dot or dot-dot */
00081     case FTS_INIT:      /* initialized only */
00082     case FTS_NSOK:      /* no stat(2) requested */
00083     case FTS_SL:        /* symbolic link */
00084     case FTS_SLNONE:    /* symbolic link without target */
00085     case FTS_W:         /* whiteout object */
00086     default:
00087         break;
00088     }
00089 
00090     return 0;
00091 }
00092 
00093 static int ftsOpts = 0;
00094 
00095 static void ftsWalk(const char * path)
00096 {
00097     const char * ftsSet[2];
00098     FTS * ftsp;
00099     FTSENT * fts;
00100     int xx;
00101 
00102 
00103     ftsSet[0] = path;
00104     ftsSet[1] = NULL;
00105 
00106     ndirs = nfiles = 0;
00107     ftsp = Fts_open((char *const *)ftsSet, ftsOpts, NULL);
00108     while((fts = Fts_read(ftsp)) != NULL)
00109         xx = ftsPrint(ftsp, fts);
00110     xx = Fts_close(ftsp);
00111 fprintf(stderr, "===== (%d/%d) dirs/files in %s\n", ndirs, nfiles, path);
00112 
00113 }
00114 
00115 static struct poptOption optionsTable[] = {
00116  { "ftsdebug", 'd', POPT_ARG_VAL,       &_fts_debug, -1,        NULL, NULL },
00117 
00118  { "comfollow", '\0', POPT_BIT_SET,     &ftsOpts, FTS_COMFOLLOW,
00119         N_("follow command line symlinks"), NULL },
00120  { "logical", '\0', POPT_BIT_SET,       &ftsOpts, FTS_LOGICAL,
00121         N_("logical walk"), NULL },
00122  { "nochdir", '\0', POPT_BIT_SET,       &ftsOpts, FTS_NOCHDIR,
00123         N_("don't change directories"), NULL },
00124  { "nostat", '\0', POPT_BIT_SET,        &ftsOpts, FTS_NOSTAT,
00125         N_("don't get stat info"), NULL },
00126  { "physical", '\0', POPT_BIT_SET,      &ftsOpts, FTS_PHYSICAL,
00127         N_("physical walk"), NULL },
00128  { "seedot", '\0', POPT_BIT_SET,        &ftsOpts, FTS_SEEDOT,
00129         N_("return dot and dot-dot"), NULL },
00130  { "xdev", '\0', POPT_BIT_SET,          &ftsOpts, FTS_XDEV,
00131         N_("don't cross devices"), NULL },
00132  { "whiteout", '\0', POPT_BIT_SET,      &ftsOpts, FTS_WHITEOUT,
00133         N_("return whiteout information"), NULL },
00134 
00135  { "ftpdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_ftp_debug, -1,
00136         N_("debug protocol data stream"), NULL},
00137  { "rpmiodebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmio_debug, -1,
00138         N_("debug rpmio I/O"), NULL},
00139  { "urldebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_url_debug, -1,
00140         N_("debug URL cache handling"), NULL},
00141  { "verbose", 'v', 0, 0, 'v',                           NULL, NULL },
00142   POPT_AUTOHELP
00143   POPT_TABLEEND
00144 };
00145 
00146 int
00147 main(int argc, const char *argv[])
00148 {
00149     poptContext optCon = poptGetContext(argv[0], argc, argv, optionsTable, 0);
00150     int rc;
00151 
00152     while ((rc = poptGetNextOpt(optCon)) > 0) {
00153         switch (rc) {
00154         case 'v':
00155             rpmIncreaseVerbosity();
00156             /*@switchbreak@*/ break;
00157         default:
00158             /*@switchbreak@*/ break;
00159         }
00160     }
00161 
00162     if (ftsOpts == 0)
00163         ftsOpts = (FTS_COMFOLLOW | FTS_LOGICAL | FTS_NOSTAT);
00164 
00165 _av_debug = -1;
00166 _ftp_debug = -1;
00167 _dav_debug = 1;
00168 #if 0
00169     ftsWalk(dirpath);
00170     ftsWalk(ftppath);
00171 #endif
00172     ftsWalk(httppath);
00173 #if 0
00174     ftsWalk(httpspath);
00175 #endif
00176 
00177 /*@i@*/ urlFreeCache();
00178 
00179     return 0;
00180 }

Generated on Tue Feb 19 22:26:37 2008 for rpm by  doxygen 1.5.1