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 }