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

Explicit warning when root is needed to upgrade DB #1908

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(geteuid() != 0) {
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(geteuid() != 0) {
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