rpm  5.4.15
rpmrepo.c
Go to the documentation of this file.
1 
5 #include "system.h"
6 
7 #if defined(WITH_DBSQL)
8 #include <dbsql.h>
9 #elif defined(WITH_SQLITE)
10 #include <sqlite3.h>
11 #ifdef __LCLINT__
12 /*@-incondefs -redecl @*/
13 extern const char *sqlite3_errmsg(sqlite3 *db)
14  /*@*/;
15 extern int sqlite3_open(
16  const char *filename, /* Database filename (UTF-8) */
17  /*@out@*/ sqlite3 **ppDb /* OUT: SQLite db handle */
18 )
19  /*@modifies *ppDb @*/;
20 extern int sqlite3_exec(
21  sqlite3 *db, /* An open database */
22  const char *sql, /* SQL to be evaluted */
23  int (*callback)(void*,int,char**,char**), /* Callback function */
24  void *, /* 1st argument to callback */
25  /*@out@*/ char **errmsg /* Error msg written here */
26 )
27  /*@modifies db, *errmsg @*/;
28 extern int sqlite3_prepare(
29  sqlite3 *db, /* Database handle */
30  const char *zSql, /* SQL statement, UTF-8 encoded */
31  int nByte, /* Maximum length of zSql in bytes. */
32  /*@out@*/ sqlite3_stmt **ppStmt, /* OUT: Statement handle */
33  /*@out@*/ const char **pzTail /* OUT: Pointer to unused portion of zSql */
34 )
35  /*@modifies *ppStmt, *pzTail @*/;
36 extern int sqlite3_reset(sqlite3_stmt *pStmt)
37  /*@modifies pStmt @*/;
38 extern int sqlite3_step(sqlite3_stmt *pStmt)
39  /*@modifies pStmt @*/;
40 extern int sqlite3_finalize(/*@only@*/ sqlite3_stmt *pStmt)
41  /*@modifies pStmt @*/;
42 extern int sqlite3_close(sqlite3 * db)
43  /*@modifies db @*/;
44 /*@=incondefs =redecl @*/
45 #endif /* __LCLINT__ */
46 #endif /* WITH_SQLITE */
47 
48 #include <rpmio_internal.h> /* XXX fdInitDigest() et al */
49 #include <rpmdir.h>
50 #include <fts.h>
51 #include <poptIO.h>
52 
53 #define _RPMREPO_INTERNAL
54 #include <rpmrepo.h>
55 
56 #include <rpmtypes.h>
57 #include <rpmtag.h>
58 #include <pkgio.h>
59 #include <rpmts.h>
60 
61 #include "debug.h"
62 
63 #ifdef __cplusplus
64 
65 #define QVA_ISSET(_qvaflags, _FLAG) ((_qvaflags) & (VERIFY_##_FLAG))
66 
67 #define VSF_ISSET(_vsflags, _FLAG) ((_vsflags) & (RPMVSF_##_FLAG))
68 #define VSF_SET(_vsflags, _FLAG) \
69  (*((unsigned *)&(_vsflags)) |= (RPMVSF_##_FLAG))
70 #define VSF_CLR(_vsflags, _FLAG) \
71  (*((unsigned *)&(_vsflags)) &= ~(RPMVSF_##_FLAG))
72 
73 #else /* __cplusplus */
74 
75 #define QVA_ISSET(_qvaflags, _FLAG) ((_qvaflags) & (VERIFY_##_FLAG))
76 
77 #define VSF_ISSET(_vsflags, _FLAG) ((_vsflags) & (RPMVSF_##_FLAG))
78 #define VSF_SET(_vsflags, _FLAG) (_vsflags) |= (RPMVSF_##_FLAG)
79 #define VSF_CLR(_vsflags, _FLAG) (_vsflags) &= ~(RPMVSF_##_FLAG)
80 
81 #endif /* __cplusplus */
82 
83 extern poptContext
84 rpmcliFini(/*@only@*/ /*@null@*/ poptContext optCon);
85 
86 /*==============================================================*/
87 
88 int
89 main(int argc, char *argv[])
90  /*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/
91  /*@modifies rpmGlobalMacroContext, fileSystem, internalState @*/
92 {
93  rpmrepo repo;
94  int rc = 1; /* assume failure. */
95  int xx;
96 
97 #if !defined(__LCLINT__) /* XXX force "rpmrepo" name. */
98  __progname = "rpmrepo";
99 #endif
100  repo = rpmrepoNew(argv, 0);
101  if (repo == NULL)
102  goto exit;
103 
104 if (_rpmrepo_debug || REPO_ISSET(DRYRUN))
105 argvPrint("repo->directories", repo->directories, NULL);
106 
107 #ifdef NOTYET
108  if (repo->basedir == NULL)
109  repo->basedir = xstrdup(repo->directories[0]);
110 #endif
111 
112  if (repo->outputdir == NULL) {
113  if (repo->directories != NULL && repo->directories[0] != NULL)
114  repo->outputdir = xstrdup(repo->directories[0]);
115  else {
116  repo->outputdir = rpmrepoRealpath(".");
117  if (repo->outputdir == NULL)
118  rpmrepoError(1, _("Realpath(%s): %s"), ".", strerror(errno));
119  }
120  }
121 
122  if (REPO_ISSET(SPLIT) && REPO_ISSET(CHECKTS))
123  rpmrepoError(1, _("--split and --checkts options are mutually exclusive"));
124 
125 #ifdef NOTYET
126  /* Add manifest(s) contents to rpm list. */
127  if (repo->manifests != NULL) {
128  const char ** av = repo->manifests;
129  const char * fn;
130  /* Load the rpm list from manifest(s). */
131  while ((fn = *av++) != NULL) {
132  /* XXX todo: parse paths from files. */
133  /* XXX todo: convert to absolute paths. */
134  /* XXX todo: check for existence. */
135  xx = argvAdd(&repo->pkglist, fn);
136  }
137  }
138 #endif
139 
140  /* Set up mire patterns (no error returns with globs, easy pie). */
141  if (mireLoadPatterns(RPMMIRE_GLOB, 0, repo->exclude_patterns, NULL,
142  &repo->excludeMire, &repo->nexcludes))
143  rpmrepoError(1, _("Error loading exclude glob patterns."));
144  if (mireLoadPatterns(RPMMIRE_GLOB, 0, repo->include_patterns, NULL,
145  &repo->includeMire, &repo->nincludes))
146  rpmrepoError(1, _("Error loading include glob patterns."));
147 
148  /* Load the rpm list from a multi-rooted directory traversal. */
149  if (repo->directories != NULL) {
150  ARGV_t pkglist = rpmrepoGetFileList(repo, repo->directories, ".rpm");
151  xx = argvAppend(&repo->pkglist, pkglist);
152  pkglist = argvFree(pkglist);
153  }
154 
155  /* XXX todo: check for duplicates in repo->pkglist? */
156  xx = argvSort(repo->pkglist, NULL);
157 
158 if (_rpmrepo_debug || REPO_ISSET(DRYRUN))
159 argvPrint("repo->pkglist", repo->pkglist, NULL);
160 
161  repo->pkgcount = argvCount(repo->pkglist);
162 
163  /* XXX enable --stats using transaction set. */
164  { rpmts ts = repo->_ts;
167  repo->_ts = ts = rpmtsCreate();
168 
169  vsflags = (rpmVSFlags) 0; /* XXX FIXME: ignore default disablers. */
170 #if defined(SUPPORT_NOSIGNATURES)
171  /* XXX todo wire up usual rpm CLI options. hotwire --nosignature for now */
172  VSF_SET(vsflags, NODSAHEADER);
173  VSF_SET(vsflags, NORSAHEADER);
174  VSF_SET(vsflags, NODSA);
175  VSF_SET(vsflags, NORSA);
176  VSF_CLR(vsflags, NEEDPAYLOAD); /* XXX needed? */
177 #endif
178  (void) rpmtsSetVSFlags(ts, vsflags);
179  }
180 
181  rc = rpmrepoTestSetupDirs(repo);
182 
183  if (rc || REPO_ISSET(DRYRUN))
184  goto exit;
185 
186  if (!REPO_ISSET(SPLIT)) {
187  rc = rpmrepoCheckTimeStamps(repo);
188  if (rc == 0) {
189  fprintf(stdout, _("repo is up to date\n"));
190  goto exit;
191  }
192  }
193 
194  if ((rc = rpmrepoDoPkgMetadata(repo)) != 0)
195  goto exit;
196  if ((rc = rpmrepoDoRepoMetadata(repo)) != 0)
197  goto exit;
198  if ((rc = rpmrepoDoFinalMove(repo)) != 0)
199  goto exit;
200 
201 exit:
202  { rpmts ts = repo->_ts;
203  (void) rpmtsFree(ts);
204  repo->_ts = NULL;
205  }
206 
207  repo = rpmrepoFree(repo);
208 
209  (void) rpmcliFini(NULL);
210 
211  return rc;
212 }
#define VSF_CLR(_vsflags, _FLAG)
Definition: rpmrepo.c:79
int rpmrepoDoFinalMove(rpmrepo repo)
Rename temporary repository to final paths.
Definition: rpmrepo.c:1269
int mireLoadPatterns(rpmMireMode mode, int tag, const char **patterns, const unsigned char *table, miRE *mirep, int *nmirep)
Load patterns from string array.
Definition: mire.c:529
const char bson_timestamp_t * ts
Definition: bson.h:1004
void rpmrepoError(int lvl, const char *fmt,...)
Print an error message and exit (if requested).
Definition: rpmrepo.c:427
char * xstrdup(const char *str)
Definition: rpmmalloc.c:321
#define __progname
Definition: system.h:363
int argvAppend(ARGV_t *argvp, ARGV_t av)
Append one argv array to another.
Definition: argv.c:216
const char ** rpmrepoGetFileList(rpmrepo repo, const char *roots[], const char *ext)
Walk file/directory trees, looking for files with an extension.
Definition: rpmrepo.c:623
static rpmVSFlags vsflags
Definition: rpmcache.c:547
int errno
const char * rpmrepoRealpath(const char *lpath)
Return realpath(3) canonicalized absolute path.
Definition: rpmrepo.c:516
int rpmrepoDoRepoMetadata(rpmrepo repo)
Write repository manifest.
Definition: rpmrepo.c:1083
int rpmrepoDoPkgMetadata(rpmrepo repo)
Write repository metadata files.
Definition: rpmrepo.c:1574
int argvCount(const ARGV_t argv)
Return no.
Definition: argv.c:71
ARGV_t argvFree(ARGV_t argv)
Destroy an argv array.
Definition: argv.c:44
int argvAdd(ARGV_t *argvp, ARGstr_t val)
Add a string to an argv array.
Definition: argv.c:199
int main(int argc, char *argv[])
Definition: rpmrepo.c:89
pgpVSFlags rpmVSFlags
Bit(s) to control digest and signature verification.
Definition: rpmts.h:35
void argvPrint(const char *msg, ARGV_t argv, FILE *fp)
Print argv array elements.
Definition: argv.c:19
int _rpmts_stats
Definition: rpmts.c:96
int rpmrepoCheckTimeStamps(rpmrepo repo)
Check that repository time stamp is newer than any contained package.
Definition: rpmrepo.c:682
rpmts rpmtsFree(rpmts ts)
Destroy transaction set, closing the database as well.
rpmts rpmtsCreate(void)
Create an empty transaction set.
Definition: rpmts.c:1470
Methods to handle package elements.
rpmrepo rpmrepoNew(char **av, int flags)
Create and load a repo wrapper.
Definition: rpmrepo.c:1902
rpmVSFlags rpmtsSetVSFlags(rpmts ts, rpmVSFlags vsflags)
Set verify signatures flag(s).
Definition: rpmts.c:845
poptContext rpmcliFini(poptContext optCon)
Destroy most everything needed by an rpm CLI executable context.
Definition: poptALL.c:523
struct rpmts_s * rpmts
The RPM Transaction Set.
Definition: rpmtypes.h:14
Structures and prototypes used for an "rpmts" transaction set.
const char * db
Definition: mongo.h:697
struct rpmrepo_s * rpmrepo
Definition: rpmrepo.h:16
int argvSort(ARGV_t argv, int(*compar)(ARGstr_t *, ARGstr_t *))
Sort an argv array.
Definition: argv.c:137
int _rpmsw_stats
Definition: rpmsw.c:20
rpmrepo rpmrepoFree(rpmrepo repo)
Destroy a repo wrapper.
#define _(Text)
Definition: system.h:29
ARGstr_t * ARGV_t
Definition: argv.h:12
int rpmrepoTestSetupDirs(rpmrepo repo)
Test for repository sanity.
Definition: rpmrepo.c:531
int _rpmrepo_debug
Definition: rpmrepo.c:66
#define VSF_SET(_vsflags, _FLAG)
Definition: rpmrepo.c:78