db: command line repositories take preference

over the ones in config file. also remove the apk_root == NULL
check as this cannot happen anymore. a valid root is always
required.
cute-signatures
Timo Teras 2009-08-06 10:17:28 +03:00
parent 7419771b02
commit 6f1de8cd53
1 changed files with 66 additions and 71 deletions

View File

@ -895,7 +895,6 @@ int apk_db_open(struct apk_database *db, const char *root, unsigned int flags)
db->cache_dir = apk_static_cache_dir;
db->permanent = 1;
if (root != NULL) {
db->root = strdup(root);
db->root_fd = openat(AT_FDCWD, db->root, O_RDONLY);
if (db->root_fd < 0 && (flags & APK_OPENF_CREATE)) {
@ -923,8 +922,7 @@ int apk_db_open(struct apk_database *db, const char *root, unsigned int flags)
msg = "Unable to create database";
goto ret_r;
}
db->lock_fd = openat(db->root_fd,
"var/lib/apk/lock",
db->lock_fd = openat(db->root_fd, "var/lib/apk/lock",
O_CREAT | O_RDWR, 0400);
}
if (db->lock_fd < 0 ||
@ -949,7 +947,6 @@ int apk_db_open(struct apk_database *db, const char *root, unsigned int flags)
goto ret_errno;
}
}
}
blob = APK_BLOB_STR("etc:*etc/init.d");
apk_blob_for_each_segment(blob, ":", add_protected_path, db);
@ -959,7 +956,6 @@ int apk_db_open(struct apk_database *db, const char *root, unsigned int flags)
db->cachetmp_fd = openat(db->cache_fd, "tmp", O_RDONLY);
db->keys_fd = openat(db->root_fd, "etc/apk/keys", O_RDONLY);
if (root != NULL) {
r = apk_db_read_state(db, flags);
if (r == -ENOENT && (flags & APK_OPENF_CREATE)) {
r = apk_db_create(db);
@ -975,6 +971,10 @@ int apk_db_open(struct apk_database *db, const char *root, unsigned int flags)
}
if (!(flags & APK_OPENF_NO_REPOS)) {
list_for_each_entry(repo, &apk_repository_list.list, list) {
r = apk_db_add_repository(db, APK_BLOB_STR(repo->url));
rr = r ?: rr;
}
if (apk_repos == NULL)
apk_repos = "etc/apk/repositories";
blob = apk_blob_from_file(db->root_fd, apk_repos);
@ -985,18 +985,13 @@ int apk_db_open(struct apk_database *db, const char *root, unsigned int flags)
rr = r ?: rr;
free(blob.ptr);
}
}
}
if (!(flags & APK_OPENF_NO_REPOS)) {
list_for_each_entry(repo, &apk_repository_list.list, list) {
r = apk_db_add_repository(db, APK_BLOB_STR(repo->url));
rr = r ?: rr;
}
if (apk_flags & APK_UPDATE_CACHE)
apk_db_index_write_nr_cache(db);
}
if (rr != 0) {
r = rr;
goto ret_r;
}
return rr;