summaryrefslogtreecommitdiff
path: root/src/add.c
diff options
context:
space:
mode:
authorTimo Teras <timo.teras@iki.fi>2009-01-17 11:07:56 +0200
committerTimo Teras <timo.teras@iki.fi>2009-01-17 11:08:48 +0200
commita98b57b1ae6f9fb04ddcc6876451632d519a0081 (patch)
treeacafb1cf2dd44fbbab363fc714582da5b9e21c62 /src/add.c
parent24b424a4580555579b11ab1d66ee3dab7751dfb5 (diff)
downloadapk-tools-a98b57b1ae6f9fb04ddcc6876451632d519a0081.tar.gz
apk-tools-a98b57b1ae6f9fb04ddcc6876451632d519a0081.tar.bz2
apk-tools-a98b57b1ae6f9fb04ddcc6876451632d519a0081.tar.xz
apk-tools-a98b57b1ae6f9fb04ddcc6876451632d519a0081.zip
db: database locking and creation to part of opening it
Add flags field to db open call. Also make error reporting quite a bit more detailed.
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;