Skip to content

Commit

Permalink
Explicit warning when root is needed to upgrade DB
Browse files Browse the repository at this point in the history
  • Loading branch information
tigergao99 committed Nov 19, 2020
1 parent d4f4037 commit 84248c5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
10 changes: 8 additions & 2 deletions libpkg/pkgdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -2510,8 +2510,14 @@ get_pragma(sqlite3 *s, const char *sql, int64_t *res, bool silence)

pkg_debug(4, "Pkgdb: running '%s'", sql);
if (sqlite3_prepare_v2(s, sql, -1, &stmt, NULL) != SQLITE_OK) {
if (!silence)
ERROR_SQLITE(s, sql);
if (!silence) {
if(strstr(sqlite3_errmsg(s), "readonly") != NULL) {
pkg_emit_error("Database upgrade is needed but pkg doesn't have write access in file %s:%d: %s, "
"please run it as root once to upgrade the DB.", __FILE__, __LINE__, sqlite3_errmsg(s));
} else {
ERROR_SQLITE(s, sql);
}
}
return (EPKG_OK);
}

Expand Down
7 changes: 6 additions & 1 deletion libpkg/repo/binary/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,12 @@ pkg_repo_binary_get_user_version(sqlite3 *sqlite, int *reposcver)
const char *sql = "PRAGMA user_version;";

if (sqlite3_prepare_v2(sqlite, sql, -1, &stmt, NULL) != SQLITE_OK) {
ERROR_SQLITE(sqlite, sql);
if(strstr(sqlite3_errmsg(sqlite), "readonly") != NULL) {
pkg_emit_error("Database upgrade is needed but pkg doesn't have write access in file %s:%d: %s, "
"please run it as root once to upgrade the DB.", __FILE__, __LINE__, sqlite3_errmsg(sqlite));
} else {
ERROR_SQLITE(sqlite, sql);
}
return (EPKG_FATAL);
}

Expand Down

0 comments on commit 84248c5

Please sign in to comment.