diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/add.c | 26 | ||||
-rw-r--r-- | src/apk_database.h | 2 | ||||
-rw-r--r-- | src/apk_package.h | 1 | ||||
-rw-r--r-- | src/database.c | 22 | ||||
-rw-r--r-- | src/package.c | 1 |
5 files changed, 37 insertions, 15 deletions
@@ -22,14 +22,32 @@ static int add_main(int argc, char **argv) return -1; for (i = 0; i < argc; i++) { - struct apk_dependency dep = { - .name = apk_db_get_name(&db, APK_BLOB_STR(argv[i])), - }; + struct apk_dependency dep; + + if (strstr(argv[i], ".apk") != NULL) { + struct apk_package *pkg; + + pkg = apk_db_pkg_add_file(&db, argv[i]); + if (pkg == NULL) { + apk_error("Unable to read '%s'", argv[i]); + goto err; + } + + dep = (struct apk_dependency) { + .name = pkg->name, + .version_mask = APK_VERSION_RESULT_MASK(APK_VERSION_EQUAL), + .version = pkg->version, + }; + } else { + dep = (struct apk_dependency) { + .name = apk_db_get_name(&db, APK_BLOB_STR(argv[i])), + }; + } apk_deps_add(&db.world, &dep); } apk_db_recalculate_and_commit(&db); +err: apk_db_close(&db); - return 0; } diff --git a/src/apk_database.h b/src/apk_database.h index 7914a03..3e70383 100644 --- a/src/apk_database.h +++ b/src/apk_database.h @@ -93,7 +93,7 @@ int apk_db_create(const char *root); int apk_db_open(struct apk_database *db, const char *root); void apk_db_close(struct apk_database *db); -int apk_db_pkg_add_file(struct apk_database *db, const char *file); +struct apk_package *apk_db_pkg_add_file(struct apk_database *db, const char *file); struct apk_package *apk_db_get_pkg(struct apk_database *db, csum_t sum); void apk_db_index_write(struct apk_database *db, int fd); diff --git a/src/apk_package.h b/src/apk_package.h index f36eb6b..3fddf67 100644 --- a/src/apk_package.h +++ b/src/apk_package.h @@ -55,6 +55,7 @@ struct apk_package { char *url, *description, *license; struct apk_dependency_array *depends; unsigned int installed_size, size; + char *filename; /* for installed packages only */ struct list_head installed_pkgs_list; diff --git a/src/database.c b/src/database.c index 513b2da..261011c 100644 --- a/src/database.c +++ b/src/database.c @@ -627,16 +627,14 @@ struct apk_package *apk_db_get_pkg(struct apk_database *db, csum_t sum) APK_BLOB_PTR_LEN((void*) sum, sizeof(csum_t))); } -int apk_db_pkg_add_file(struct apk_database *db, const char *file) +struct apk_package *apk_db_pkg_add_file(struct apk_database *db, const char *file) { struct apk_package *info; info = apk_pkg_read(db, file); - if (info == NULL) - return FALSE; - - apk_db_pkg_add(db, info); - return TRUE; + if (info != NULL) + apk_db_pkg_add(db, info); + return info; } static int write_index_entry(apk_hash_item item, void *ctx) @@ -864,11 +862,15 @@ int apk_db_install_pkg(struct apk_database *db, } /* Install the new stuff */ - snprintf(file, sizeof(file), - "%s/%s-%s.apk", - db->repos[0].url, newpkg->name->name, newpkg->version); + if (newpkg->filename == NULL) { + snprintf(file, sizeof(file), + "%s/%s-%s.apk", + db->repos[0].url, newpkg->name->name, newpkg->version); + + fd = open(file, O_RDONLY); + } else + fd = open(newpkg->filename, O_RDONLY); - fd = open(file, O_RDONLY); if (fd < 0) { apk_error("%s: %s", file, strerror(errno)); return errno; diff --git a/src/package.c b/src/package.c index 56f0f79..d419596 100644 --- a/src/package.c +++ b/src/package.c @@ -373,6 +373,7 @@ struct apk_package *apk_pkg_read(struct apk_database *db, const char *file) }; apk_deps_add(&ctx.pkg->depends, &dep); } + ctx.pkg->filename = strdup(file); return ctx.pkg; err: |