Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert back to implicit database creation for now #1654

Merged
merged 1 commit into from Apr 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/backend/ndb/glue.c
Expand Up @@ -133,8 +133,8 @@ static int ndb_Open(rpmdb rdb, rpmDbiTagVal rpmtag, dbiIndex * dbip, int flags)
rc = rpmpkgOpen(&pkgdb, path, oflags, rdb->db_perms);
else
rc = rpmpkgSalvage(&pkgdb, path);
if (rc && errno == ENOENT && (oflags == O_RDWR) && (rdb->db_flags & RPMDB_FLAG_SALVAGE) == 0) {
oflags |= O_CREAT;
if (rc && errno == ENOENT && (rdb->db_flags & RPMDB_FLAG_SALVAGE) == 0) {
oflags = O_RDWR|O_CREAT;
dbi->dbi_flags |= DBI_CREATED;
rc = rpmpkgOpen(&pkgdb, path, oflags, rdb->db_perms);
}
Expand Down
21 changes: 16 additions & 5 deletions lib/backend/sqlite.c
Expand Up @@ -134,17 +134,28 @@ static int sqlite_init(rpmdb rdb, const char * dbhome)
if (rdb->db_dbenv == NULL) {
dbfile = rpmGenPath(dbhome, rdb->db_ops->path, NULL);
sqlite3 *sdb = NULL;
int flags = 0;
int xx, flags = 0;
int retry_open = 1;
if ((rdb->db_mode & O_ACCMODE) == O_RDONLY)
flags |= SQLITE_OPEN_READONLY;
else
flags |= (SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE);

if (sqlite3_open_v2(dbfile, &sdb, flags, NULL) != SQLITE_OK ) {
while (retry_open--) {
xx = sqlite3_open_v2(dbfile, &sdb, flags, NULL);
/* Attempt to create if missing, discarding OPEN_READONLY (!) */
if (xx == SQLITE_CANTOPEN && (flags & SQLITE_OPEN_READONLY)) {
/* Sqlite allocates resources even on failure to open (!) */
sqlite3_close(sdb);
flags &= ~SQLITE_OPEN_READONLY;
flags |= (SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE);
retry_open++;
}
}

if (xx != SQLITE_OK) {
rpmlog(RPMLOG_ERR, _("Unable to open sqlite database %s: %s\n"),
dbfile, sqlite3_errmsg(sdb));
/* Sqlite allocates resources even on failure to open (!) */
sqlite3_close(sdb);
dbfile, sqlite3_errstr(xx));
rc = 1;
goto exit;
}
Expand Down
6 changes: 0 additions & 6 deletions lib/depends.c
Expand Up @@ -4,8 +4,6 @@

#include "system.h"

#include <fcntl.h>

#include <rpm/rpmlib.h> /* rpmVersionCompare, rpmlib provides */
#include <rpm/rpmtag.h>
#include <rpm/rpmlog.h>
Expand Down Expand Up @@ -416,10 +414,6 @@ static int addPackage(rpmts ts, Header h,
if (isSource)
op = RPMTE_INSTALL;

/* Ensure database creation on initial installs */
if (!isSource && rpmtsGetDBMode(ts) == O_RDONLY)
rpmtsSetDBMode(ts, (O_RDWR|O_CREAT));

/* Do lazy (readonly?) open of rpm database for upgrades. */
if (op != RPMTE_INSTALL && rpmtsGetRdb(ts) == NULL && rpmtsGetDBMode(ts) != -1) {
if ((ec = rpmtsOpenDB(ts, rpmtsGetDBMode(ts))) != 0)
Expand Down
5 changes: 2 additions & 3 deletions lib/rpmdb.c
Expand Up @@ -487,7 +487,7 @@ static int openDatabase(const char * prefix,
int mode, int perms, int flags)
{
rpmdb db;
int rc = 0;
int rc;
int justCheck = flags & RPMDB_FLAG_JUSTCHECK;

if (dbp)
Expand All @@ -503,8 +503,7 @@ static int openDatabase(const char * prefix,
rpmdbRock = db;

/* Try to ensure db home exists, error out if we can't even create */
if ((mode & O_ACCMODE) != O_RDONLY)
rc = rpmioMkpath(rpmdbHome(db), 0755, getuid(), getgid());
rc = rpmioMkpath(rpmdbHome(db), 0755, getuid(), getgid());
if (rc == 0) {
/* Open just bare minimum when rebuilding a potentially damaged db */
int justPkgs = (db->db_flags & RPMDB_FLAG_REBUILD) &&
Expand Down
2 changes: 1 addition & 1 deletion tests/rpmdb.at
Expand Up @@ -50,7 +50,7 @@ RPMTEST_SETUP
runroot rpm \
-qa
],
[1],
[0],
[],
[ignore])
AT_CLEANUP
Expand Down