Skip to content
Snippets Groups Projects
Commit aee61d0a authored by Timo Teräs's avatar Timo Teräs
Browse files

db: try creating db if locking fails

Otherwise creating rootfs from scratch with --initdb cannot be locked
due to the lock file path missing.
parent 93cdb993
No related branches found
No related tags found
No related merge requests found
......@@ -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";
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment