rpm 5.3.12
tools/rpmrepo.c
Go to the documentation of this file.
00001 
00005 #include "system.h"
00006 
00007 #if defined(WITH_DBSQL)
00008 #include <db51/dbsql.h>
00009 #elif defined(WITH_SQLITE)
00010 #include <sqlite3.h>
00011 #ifdef  __LCLINT__
00012 /*@-incondefs -redecl @*/
00013 extern const char *sqlite3_errmsg(sqlite3 *db)
00014         /*@*/;
00015 extern int sqlite3_open(
00016   const char *filename,            /* Database filename (UTF-8) */
00017   /*@out@*/ sqlite3 **ppDb         /* OUT: SQLite db handle */
00018 )
00019         /*@modifies *ppDb @*/;
00020 extern int sqlite3_exec(
00021   sqlite3 *db,                     /* An open database */
00022   const char *sql,                 /* SQL to be evaluted */
00023   int (*callback)(void*,int,char**,char**),  /* Callback function */
00024   void *,                          /* 1st argument to callback */
00025   /*@out@*/ char **errmsg          /* Error msg written here */
00026 )
00027         /*@modifies db, *errmsg @*/;
00028 extern int sqlite3_prepare(
00029   sqlite3 *db,                     /* Database handle */
00030   const char *zSql,                /* SQL statement, UTF-8 encoded */
00031   int nByte,                       /* Maximum length of zSql in bytes. */
00032   /*@out@*/ sqlite3_stmt **ppStmt, /* OUT: Statement handle */
00033   /*@out@*/ const char **pzTail    /* OUT: Pointer to unused portion of zSql */
00034 )
00035         /*@modifies *ppStmt, *pzTail @*/;
00036 extern int sqlite3_reset(sqlite3_stmt *pStmt)
00037         /*@modifies pStmt @*/;
00038 extern int sqlite3_step(sqlite3_stmt *pStmt)
00039         /*@modifies pStmt @*/;
00040 extern int sqlite3_finalize(/*@only@*/ sqlite3_stmt *pStmt)
00041         /*@modifies pStmt @*/;
00042 extern int sqlite3_close(sqlite3 * db)
00043         /*@modifies db @*/;
00044 /*@=incondefs =redecl @*/
00045 #endif  /* __LCLINT__ */
00046 #endif  /* WITH_SQLITE */
00047 
00048 #include <rpmio_internal.h>     /* XXX fdInitDigest() et al */
00049 #include <rpmdir.h>
00050 #include <fts.h>
00051 #include <poptIO.h>
00052 
00053 #define _RPMREPO_INTERNAL
00054 #include <rpmrepo.h>
00055 
00056 #include <rpmtypes.h>
00057 #include <rpmtag.h>
00058 #include <pkgio.h>
00059 #include <rpmts.h>
00060 
00061 #include "debug.h"
00062 
00063 /*==============================================================*/
00064 
00065 int
00066 main(int argc, char *argv[])
00067         /*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/
00068         /*@modifies rpmGlobalMacroContext, fileSystem, internalState @*/
00069 {
00070     rpmrepo repo;
00071     int rc = 1;         /* assume failure. */
00072     int xx;
00073 
00074 #if !defined(__LCLINT__)        /* XXX force "rpmrepo" name. */
00075     __progname = "rpmrepo";
00076 #endif
00077     repo = rpmrepoNew(argv, 0);
00078     if (repo == NULL)
00079         goto exit;
00080 
00081 if (_rpmrepo_debug || REPO_ISSET(DRYRUN))
00082 argvPrint("repo->directories", repo->directories, NULL);
00083 
00084 #ifdef  NOTYET
00085     if (repo->basedir == NULL)
00086         repo->basedir = xstrdup(repo->directories[0]);
00087 #endif
00088 
00089     if (repo->outputdir == NULL) {
00090         if (repo->directories != NULL && repo->directories[0] != NULL)
00091             repo->outputdir = xstrdup(repo->directories[0]);
00092         else {
00093             repo->outputdir = rpmrepoRealpath(".");
00094             if (repo->outputdir == NULL)
00095                 rpmrepoError(1, _("Realpath(%s): %s"), ".", strerror(errno));
00096         }
00097     }
00098 
00099     if (REPO_ISSET(SPLIT) && REPO_ISSET(CHECKTS))
00100         rpmrepoError(1, _("--split and --checkts options are mutually exclusive"));
00101 
00102 #ifdef  NOTYET
00103     /* Add manifest(s) contents to rpm list. */
00104     if (repo->manifests != NULL) {
00105         const char ** av = repo->manifests;
00106         const char * fn;
00107         /* Load the rpm list from manifest(s). */
00108         while ((fn = *av++) != NULL) {
00109             /* XXX todo: parse paths from files. */
00110             /* XXX todo: convert to absolute paths. */
00111             /* XXX todo: check for existence. */
00112             xx = argvAdd(&repo->pkglist, fn);
00113         }
00114     }
00115 #endif
00116 
00117     /* Set up mire patterns (no error returns with globs, easy pie). */
00118     if (mireLoadPatterns(RPMMIRE_GLOB, 0, repo->exclude_patterns, NULL,
00119                 &repo->excludeMire, &repo->nexcludes))
00120         rpmrepoError(1, _("Error loading exclude glob patterns."));
00121     if (mireLoadPatterns(RPMMIRE_GLOB, 0, repo->include_patterns, NULL,
00122                 &repo->includeMire, &repo->nincludes))
00123         rpmrepoError(1, _("Error loading include glob patterns."));
00124 
00125     /* Load the rpm list from a multi-rooted directory traversal. */
00126     if (repo->directories != NULL) {
00127         ARGV_t pkglist = rpmrepoGetFileList(repo, repo->directories, ".rpm");
00128         xx = argvAppend(&repo->pkglist, pkglist);
00129         pkglist = argvFree(pkglist);
00130     }
00131 
00132     /* XXX todo: check for duplicates in repo->pkglist? */
00133     xx = argvSort(repo->pkglist, NULL);
00134 
00135 if (_rpmrepo_debug || REPO_ISSET(DRYRUN))
00136 argvPrint("repo->pkglist", repo->pkglist, NULL);
00137 
00138     repo->pkgcount = argvCount(repo->pkglist);
00139 
00140     /* XXX enable --stats using transaction set. */
00141     {   rpmts ts = repo->_ts;
00142         _rpmts_stats = _rpmsw_stats;
00143         repo->_ts = ts = rpmtsCreate();
00144 
00145     /* XXX todo wire up usual rpm CLI options. hotwire --nosignature for now */
00146         (void) rpmtsSetVSFlags(ts, _RPMVSF_NOSIGNATURES);
00147     }
00148 
00149     rc = rpmrepoTestSetupDirs(repo);
00150         
00151     if (rc || REPO_ISSET(DRYRUN))
00152         goto exit;
00153 
00154     if (!REPO_ISSET(SPLIT)) {
00155         rc = rpmrepoCheckTimeStamps(repo);
00156         if (rc == 0) {
00157             fprintf(stdout, _("repo is up to date\n"));
00158             goto exit;
00159         }
00160     }
00161 
00162     if ((rc = rpmrepoDoPkgMetadata(repo)) != 0)
00163         goto exit;
00164     if ((rc = rpmrepoDoRepoMetadata(repo)) != 0)
00165         goto exit;
00166     if ((rc = rpmrepoDoFinalMove(repo)) != 0)
00167         goto exit;
00168 
00169 exit:
00170     {   rpmts ts = repo->_ts;
00171         (void) rpmtsFree(ts); 
00172         repo->_ts = NULL;
00173     }
00174 
00175     repo = rpmrepoFree(repo);
00176 
00177     tagClean(NULL);
00178 
00179     return rc;
00180 }