summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTimo Teras <timo.teras@iki.fi>2009-01-19 21:19:36 +0200
committerTimo Teras <timo.teras@iki.fi>2009-01-19 21:19:36 +0200
commitaee61d0a0b37e56457d1c4cfd48c04552e9ed315 (patch)
tree5227d83f3c009907582b5ef43a59a6ca762ca074
parent93cdb993a19066ac22564d62f83228c87d2ed1c7 (diff)
downloadapk-tools-aee61d0a0b37e56457d1c4cfd48c04552e9ed315.tar.bz2
apk-tools-aee61d0a0b37e56457d1c4cfd48c04552e9ed315.tar.xz
db: try creating db if locking fails
Otherwise creating rootfs from scratch with --initdb cannot be locked due to the lock file path missing.
-rw-r--r--src/database.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/database.c b/src/database.c
index 118870d..3e897d2 100644
--- a/src/database.c
+++ b/src/database.c
@@ -648,6 +648,16 @@ int apk_db_open(struct apk_database *db, const char *root, unsigned int flags)
if (flags & APK_OPENF_WRITE) {
db->lock_fd = open("var/lib/apk/lock",
O_CREAT | O_WRONLY, 0400);
+ if (db->lock_fd < 0 && errno == ENOENT &&
+ (flags & APK_OPENF_CREATE)) {
+ r = apk_db_create(db);
+ if (r != 0) {
+ msg = "Unable to create database";
+ goto ret_r;
+ }
+ db->lock_fd = open("var/lib/apk/lock",
+ O_CREAT | O_WRONLY, 0400);
+ }
if (db->lock_fd < 0 ||
flock(db->lock_fd, LOCK_EX | LOCK_NB) < 0) {
msg = "Unable to lock database";