summaryrefslogtreecommitdiff
path: root/src/add.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/add.c')
-rw-r--r--src/add.c27
1 files changed, 5 insertions, 22 deletions
diff --git a/src/add.c b/src/add.c
index 9101db2..7aa0b23 100644
--- a/src/add.c
+++ b/src/add.c
@@ -14,10 +14,8 @@
#include "apk_applet.h"
#include "apk_database.h"
-#define FLAG_INITDB 0x0001
-
struct add_ctx {
- unsigned int flags;
+ unsigned int open_flags;
};
static int add_parse(void *ctx, int optch, int optindex, const char *optarg)
@@ -26,7 +24,7 @@ static int add_parse(void *ctx, int optch, int optindex, const char *optarg)
switch (optch) {
case 0x10000:
- actx->flags |= FLAG_INITDB;
+ actx->open_flags |= APK_OPENF_CREATE;
break;
case 'u':
apk_upgrade = 1;
@@ -43,24 +41,9 @@ static int add_main(void *ctx, int argc, char **argv)
struct apk_database db;
int i, r, ret = 1;
- r = apk_db_open(&db, apk_root);
- if ((r == -ENOENT) && (actx->flags & FLAG_INITDB)) {
- if (strcmp(apk_root, "/") == 0) {
- apk_error("Will not recreate system root.");
- return 1;
- }
- r = apk_db_create(apk_root);
- if (r != 0) {
- apk_error("Failed to create apkdb: %s",
- strerror(-r));
- return 1;
- }
- r = apk_db_open(&db, apk_root);
- }
- if (r != 0) {
- apk_error("APK database not present (use --initdb to create one)");
- return 1;
- }
+ r = apk_db_open(&db, apk_root, actx->open_flags | APK_OPENF_WRITE);
+ if (r != 0)
+ return r;
for (i = 0; i < argc; i++) {
struct apk_dependency dep;