summaryrefslogtreecommitdiff
path: root/src/database.c
diff options
context:
space:
mode:
authorTimo Teräs <timo.teras@iki.fi>2012-02-23 17:04:51 +0200
committerTimo Teräs <timo.teras@iki.fi>2012-02-23 17:04:51 +0200
commit7392acb95ea7be1317892aad1b69a01382ee3f5c (patch)
treeb97a25dce86bedc25f07f0f0275b67519c0521a2 /src/database.c
parenta9a84215c70c746b2f6a6b3c58c338730100666c (diff)
downloadapk-tools-7392acb95ea7be1317892aad1b69a01382ee3f5c.tar.gz
apk-tools-7392acb95ea7be1317892aad1b69a01382ee3f5c.tar.bz2
apk-tools-7392acb95ea7be1317892aad1b69a01382ee3f5c.tar.xz
apk-tools-7392acb95ea7be1317892aad1b69a01382ee3f5c.zip
db: keep architecture in $ROOT/etc/apk/arch
This we use proper arch in case modifying chroot installation.
Diffstat (limited to 'src/database.c')
-rw-r--r--src/database.c25
1 files changed, 19 insertions, 6 deletions
diff --git a/src/database.c b/src/database.c
index da3dcb9..ca6c524 100644
--- a/src/database.c
+++ b/src/database.c
@@ -55,6 +55,7 @@ static const char * const apk_lock_file = "var/lock/apkdb";
static const char * const apk_world_file = "etc/apk/world";
static const char * const apk_world_file_tmp = "etc/apk/world.new";
static const char * const apk_world_file_old = "var/lib/apk/world";
+static const char * const apk_arch_file = "etc/apk/arch";
static const char * const apk_scripts_file = "lib/apk/db/scripts.tar";
static const char * const apk_scripts_file_tmp = "lib/apk/db/scripts.tar.new";
@@ -1339,7 +1340,7 @@ int apk_db_open(struct apk_database *db, struct apk_db_options *dbopts)
struct apk_bstream *bs;
struct statfs stfs;
apk_blob_t blob;
- int r, fd;
+ int r, fd, write_arch = FALSE;
memset(db, 0, sizeof(*db));
if (apk_flags & APK_SIMULATE) {
@@ -1365,11 +1366,6 @@ int apk_db_open(struct apk_database *db, struct apk_db_options *dbopts)
/* Get first repository tag (the NULL tag) */
apk_db_get_tag_id(db, APK_BLOB_NULL);
- if (dbopts->root && dbopts->arch) {
- db->arch = apk_blob_atomize(APK_BLOB_STR(dbopts->arch));
- } else {
- db->arch = apk_blob_atomize(APK_BLOB_STR(APK_DEFAULT_ARCH));
- }
db->root = strdup(dbopts->root ?: "/");
db->root_fd = openat(AT_FDCWD, db->root, O_RDONLY | O_CLOEXEC);
if (db->root_fd < 0 && (dbopts->open_flags & APK_OPENF_CREATE)) {
@@ -1384,6 +1380,21 @@ int apk_db_open(struct apk_database *db, struct apk_db_options *dbopts)
stfs.f_type == 0x01021994 /* TMPFS_MAGIC */)
db->permanent = 0;
+ if (dbopts->root && dbopts->arch) {
+ db->arch = apk_blob_atomize(APK_BLOB_STR(dbopts->arch));
+ write_arch = TRUE;
+ } else {
+ apk_blob_t arch;
+ arch = apk_blob_from_file(db->root_fd, apk_arch_file);
+ if (!APK_BLOB_IS_NULL(arch)) {
+ db->arch = apk_blob_atomize_dup(apk_blob_trim(arch));
+ free(arch.ptr);
+ } else {
+ db->arch = apk_blob_atomize(APK_BLOB_STR(APK_DEFAULT_ARCH));
+ write_arch = TRUE;
+ }
+ }
+
apk_id_cache_init(&db->id_cache, db->root_fd);
if (dbopts->open_flags & APK_OPENF_WRITE) {
@@ -1423,6 +1434,8 @@ int apk_db_open(struct apk_database *db, struct apk_db_options *dbopts)
} else
goto ret_errno;
}
+ if (write_arch)
+ apk_blob_to_file(db->root_fd, apk_arch_file, *db->arch, APK_BTF_ADD_EOL);
}
blob = APK_BLOB_STR("+etc\n" "@etc/init.d\n");