rpm  5.4.10
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 /*==============================================================*/
84 
85 int
86 main(int argc, char *argv[])
87  /*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/
88  /*@modifies rpmGlobalMacroContext, fileSystem, internalState @*/
89 {
90  rpmrepo repo;
91  int rc = 1; /* assume failure. */
92  int xx;
93 
94 #if !defined(__LCLINT__) /* XXX force "rpmrepo" name. */
95  __progname = "rpmrepo";
96 #endif
97  repo = rpmrepoNew(argv, 0);
98  if (repo == NULL)
99  goto exit;
100 
101 if (_rpmrepo_debug || REPO_ISSET(DRYRUN))
102 argvPrint("repo->directories", repo->directories, NULL);
103 
104 #ifdef NOTYET
105  if (repo->basedir == NULL)
106  repo->basedir = xstrdup(repo->directories[0]);
107 #endif
108 
109  if (repo->outputdir == NULL) {
110  if (repo->directories != NULL && repo->directories[0] != NULL)
111  repo->outputdir = xstrdup(repo->directories[0]);
112  else {
113  repo->outputdir = rpmrepoRealpath(".");
114  if (repo->outputdir == NULL)
115  rpmrepoError(1, _("Realpath(%s): %s"), ".", strerror(errno));
116  }
117  }
118 
119  if (REPO_ISSET(SPLIT) && REPO_ISSET(CHECKTS))
120  rpmrepoError(1, _("--split and --checkts options are mutually exclusive"));
121 
122 #ifdef NOTYET
123  /* Add manifest(s) contents to rpm list. */
124  if (repo->manifests != NULL) {
125  const char ** av = repo->manifests;
126  const char * fn;
127  /* Load the rpm list from manifest(s). */
128  while ((fn = *av++) != NULL) {
129  /* XXX todo: parse paths from files. */
130  /* XXX todo: convert to absolute paths. */
131  /* XXX todo: check for existence. */
132  xx = argvAdd(&repo->pkglist, fn);
133  }
134  }
135 #endif
136 
137  /* Set up mire patterns (no error returns with globs, easy pie). */
138  if (mireLoadPatterns(RPMMIRE_GLOB, 0, repo->exclude_patterns, NULL,
139  &repo->excludeMire, &repo->nexcludes))
140  rpmrepoError(1, _("Error loading exclude glob patterns."));
141  if (mireLoadPatterns(RPMMIRE_GLOB, 0, repo->include_patterns, NULL,
142  &repo->includeMire, &repo->nincludes))
143  rpmrepoError(1, _("Error loading include glob patterns."));
144 
145  /* Load the rpm list from a multi-rooted directory traversal. */
146  if (repo->directories != NULL) {
147  ARGV_t pkglist = rpmrepoGetFileList(repo, repo->directories, ".rpm");
148  xx = argvAppend(&repo->pkglist, pkglist);
149  pkglist = argvFree(pkglist);
150  }
151 
152  /* XXX todo: check for duplicates in repo->pkglist? */
153  xx = argvSort(repo->pkglist, NULL);
154 
155 if (_rpmrepo_debug || REPO_ISSET(DRYRUN))
156 argvPrint("repo->pkglist", repo->pkglist, NULL);
157 
158  repo->pkgcount = argvCount(repo->pkglist);
159 
160  /* XXX enable --stats using transaction set. */
161  { rpmts ts = repo->_ts;
164  repo->_ts = ts = rpmtsCreate();
165 
166  vsflags = (rpmVSFlags) 0; /* XXX FIXME: ignore default disablers. */
167 #if defined(SUPPORT_NOSIGNATURES)
168  /* XXX todo wire up usual rpm CLI options. hotwire --nosignature for now */
169  VSF_SET(vsflags, NODSAHEADER);
170  VSF_SET(vsflags, NORSAHEADER);
171  VSF_SET(vsflags, NODSA);
172  VSF_SET(vsflags, NORSA);
173  VSF_CLR(vsflags, NEEDPAYLOAD); /* XXX needed? */
174 #endif
175  (void) rpmtsSetVSFlags(ts, vsflags);
176  }
177 
178  rc = rpmrepoTestSetupDirs(repo);
179 
180  if (rc || REPO_ISSET(DRYRUN))
181  goto exit;
182 
183  if (!REPO_ISSET(SPLIT)) {
184  rc = rpmrepoCheckTimeStamps(repo);
185  if (rc == 0) {
186  fprintf(stdout, _("repo is up to date\n"));
187  goto exit;
188  }
189  }
190 
191  if ((rc = rpmrepoDoPkgMetadata(repo)) != 0)
192  goto exit;
193  if ((rc = rpmrepoDoRepoMetadata(repo)) != 0)
194  goto exit;
195  if ((rc = rpmrepoDoFinalMove(repo)) != 0)
196  goto exit;
197 
198 exit:
199  { rpmts ts = repo->_ts;
200  (void) rpmtsFree(ts);
201  repo->_ts = NULL;
202  }
203 
204  repo = rpmrepoFree(repo);
205 
206  tagClean(NULL);
207 
208  return rc;
209 }
#define VSF_CLR(_vsflags, _FLAG)
Definition: rpmrepo.c:79
int rpmrepoDoFinalMove(rpmrepo repo)
Rename temporary repository to final paths.
Definition: rpmrepo.c:1264
void tagClean(headerTagIndices _rpmTags)
Free memory in header tag indices.
Definition: tagname.c:461
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:531
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:322
#define __progname
Definition: system.h:428
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:622
static rpmVSFlags vsflags
Definition: rpmcache.c:547
int errno
const char * rpmrepoRealpath(const char *lpath)
Return realpath(3) canonicalized absolute path.
Definition: rpmrepo.c:515
int rpmrepoDoRepoMetadata(rpmrepo repo)
Write repository manifest.
Definition: rpmrepo.c:1078
int rpmrepoDoPkgMetadata(rpmrepo repo)
Write repository metadata files.
Definition: rpmrepo.c:1569
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:86
pgpVSFlags rpmVSFlags
Bit(s) to control digest and signature verification.
Definition: rpmts.h:30
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:681
rpmts rpmtsFree(rpmts ts)
Destroy transaction set, closing the database as well.
rpmts rpmtsCreate(void)
Create an empty transaction set.
Definition: rpmts.c:1480
Methods to handle package elements.
rpmrepo rpmrepoNew(char **av, int flags)
Create and load a repo wrapper.
Definition: rpmrepo.c:1897
rpmVSFlags rpmtsSetVSFlags(rpmts ts, rpmVSFlags vsflags)
Set verify signatures flag(s).
Definition: rpmts.c:843
struct rpmts_s * rpmts
The RPM Transaction Set.
Definition: rpmtypes.h:14
Structures and prototypes used for an "rpmts" transaction set.
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:30
ARGstr_t * ARGV_t
Definition: argv.h:9
int rpmrepoTestSetupDirs(rpmrepo repo)
Test for repository sanity.
Definition: rpmrepo.c:530
int _rpmrepo_debug
Definition: rpmrepo.c:66
#define VSF_SET(_vsflags, _FLAG)
Definition: rpmrepo.c:78