Skip to content

Commit 84248c5

Browse files
committed
Explicit warning when root is needed to upgrade DB
1 parent d4f4037 commit 84248c5

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

libpkg/pkgdb.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2510,8 +2510,14 @@ get_pragma(sqlite3 *s, const char *sql, int64_t *res, bool silence)
25102510

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

libpkg/repo/binary/init.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,12 @@ pkg_repo_binary_get_user_version(sqlite3 *sqlite, int *reposcver)
8585
const char *sql = "PRAGMA user_version;";
8686

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

0 commit comments

Comments
 (0)