summaryrefslogtreecommitdiff
path: root/src/database.c
diff options
context:
space:
mode:
authorTimo Teras <timo.teras@iki.fi>2009-01-13 20:58:08 +0200
committerTimo Teras <timo.teras@iki.fi>2009-01-13 20:58:08 +0200
commit3309eaa90008dcd4febf907f619a2f4f060d08b6 (patch)
treee49dbfbb7c534060170bada25b06ecd14dfcfb5b /src/database.c
parenta59347fdacd80e26394e519e578ba73de729e7a2 (diff)
downloadapk-tools-3309eaa90008dcd4febf907f619a2f4f060d08b6.tar.gz
apk-tools-3309eaa90008dcd4febf907f619a2f4f060d08b6.tar.bz2
apk-tools-3309eaa90008dcd4febf907f619a2f4f060d08b6.tar.xz
apk-tools-3309eaa90008dcd4febf907f619a2f4f060d08b6.zip
add: --initdb to replace create applet
Diffstat (limited to 'src/database.c')
-rw-r--r--src/database.c23
1 files changed, 10 insertions, 13 deletions
diff --git a/src/database.c b/src/database.c
index 6c21f50..d0207f2 100644
--- a/src/database.c
+++ b/src/database.c
@@ -511,10 +511,8 @@ int apk_db_create(const char *root)
int fd;
fchdir(apk_cwd_fd);
- if (chdir(root) == -1) {
- apk_error("%s: %s", root, strerror(errno));
- return -1;
- }
+ if (chdir(root) == -1)
+ return -errno;
mkdir("tmp", 01777);
mkdir("dev", 0755);
@@ -525,7 +523,7 @@ int apk_db_create(const char *root)
fd = creat("var/lib/apk/world", 0600);
if (fd < 0)
- return -1;
+ return -errno;
write(fd, deps.ptr, deps.len);
close(fd);
@@ -551,10 +549,8 @@ static int apk_db_read_state(struct apk_database *db)
fchdir(db->root_fd);
blob = apk_blob_from_file("var/lib/apk/world");
- if (APK_BLOB_IS_NULL(blob)) {
- apk_error("Please run 'apk create' to initialize root");
- return -1;
- }
+ if (APK_BLOB_IS_NULL(blob))
+ return -ENOENT;
apk_deps_parse(db, &db->world, blob);
free(blob.ptr);
@@ -585,6 +581,7 @@ int apk_db_open(struct apk_database *db, const char *root)
{
apk_blob_t blob;
const char *apk_repos = getenv("APK_REPOS");
+ int r;
memset(db, 0, sizeof(*db));
apk_hash_init(&db->available.names, &pkg_name_hash_ops, 1000);
@@ -597,17 +594,17 @@ int apk_db_open(struct apk_database *db, const char *root)
db->root = strdup(root);
db->root_fd = open(root, O_RDONLY);
if (db->root_fd < 0) {
- apk_error("%s: %s", root, strerror(errno));
free(db->root);
- return -1;
+ return -errno;
}
}
blob = APK_BLOB_STR("etc:-etc/init.d");
apk_blob_for_each_segment(blob, ":", add_protected_path, db);
- if (apk_db_read_state(db) != 0)
- return -1;
+ r = apk_db_read_state(db);
+ if (r != 0)
+ return r;
if (apk_repos == NULL)
apk_repos="/etc/apk/repositories";