diff options
author | Timo Teras <timo.teras@iki.fi> | 2008-11-27 16:59:04 +0200 |
---|---|---|
committer | Timo Teras <timo.teras@iki.fi> | 2008-11-27 16:59:04 +0200 |
commit | 1a7f3e3678844165d2660ebff09da26b9ba01576 (patch) | |
tree | d2b960a3612249d1ac975e18bb98096a6e2a2df5 /src/database.c | |
parent | 8e23a2ba4eb7f6192c6bce8a6da81004803eca3f (diff) | |
download | apk-tools-1a7f3e3678844165d2660ebff09da26b9ba01576.tar.gz apk-tools-1a7f3e3678844165d2660ebff09da26b9ba01576.tar.bz2 apk-tools-1a7f3e3678844165d2660ebff09da26b9ba01576.tar.xz apk-tools-1a7f3e3678844165d2660ebff09da26b9ba01576.zip |
various: use apk_istream api
Diffstat (limited to 'src/database.c')
-rw-r--r-- | src/database.c | 29 |
1 files changed, 11 insertions, 18 deletions
diff --git a/src/database.c b/src/database.c index 4ed3ece..2376249 100644 --- a/src/database.c +++ b/src/database.c @@ -244,7 +244,7 @@ static struct apk_db_file *apk_db_file_get(struct apk_database *db, return file; } -static int apk_db_read_fdb(struct apk_database *db, int fd) +static int apk_db_read_fdb(struct apk_database *db, struct apk_istream *is) { struct apk_package *pkg = NULL; struct apk_db_dir *dir = NULL; @@ -260,7 +260,7 @@ static int apk_db_read_fdb(struct apk_database *db, int fd) r = APK_BLOB_PTR_LEN(buf, 0); while (1) { - n = read(fd, &r.ptr[r.len], sizeof(buf) - r.len); + n = is->read(is, &r.ptr[r.len], sizeof(buf) - r.len); if (n <= 0) break; r.len += n; @@ -450,9 +450,7 @@ int apk_db_create(const char *root) static int apk_db_read_state(struct apk_database *db) { struct apk_istream *is; - struct stat st; - char *buf; - int fd; + apk_blob_t blob; if (db->root == NULL) return 0; @@ -467,23 +465,18 @@ static int apk_db_read_state(struct apk_database *db) */ fchdir(db->root_fd); - fd = open("var/lib/apk/world", O_RDONLY); - if (fd < 0) { + 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; } + apk_deps_parse(db, &db->world, blob); + free(blob.ptr); - fstat(fd, &st); - buf = malloc(st.st_size); - read(fd, buf, st.st_size); - apk_deps_parse(db, &db->world, - APK_BLOB_PTR_LEN(buf, st.st_size)); - close(fd); - - fd = open("var/lib/apk/files", O_RDONLY); - if (fd >= 0) { - apk_db_read_fdb(db, fd); - close(fd); + is = apk_istream_from_file("var/lib/apk/files"); + if (is != NULL) { + apk_db_read_fdb(db, is); + is->close(is); } is = apk_istream_from_file("var/lib/apk/scripts"); |