Commit 718ef307 authored by Timo Teräs's avatar Timo Teräs

add: fixes to installing non-repository package

make sure cache is enabled on non-permanent rootfs setups.
some optimizations and fixes too.
parent 9b77c053
......@@ -116,17 +116,27 @@ static int add_main(void *ctx, int argc, char **argv)
struct apk_dependency dep;
if (strstr(argv[i], ".apk") != NULL) {
struct apk_package *pkg;
struct apk_package *pkg = NULL;
struct apk_sign_ctx sctx;
apk_sign_ctx_init(&sctx, APK_SIGN_VERIFY, NULL);
if (!apk_db_cache_active(&db) &&
!apk_db_permanent(&db) &&
!(apk_flags & APK_FORCE)) {
apk_error("Use --force or enable package "
"caching to install non-repository "
"packages.");
goto err;
}
/* FIXME: should verify the package too */
apk_sign_ctx_init(&sctx, APK_SIGN_GENERATE, NULL);
r = apk_pkg_read(&db, argv[i], &sctx, &pkg);
apk_sign_ctx_free(&sctx);
if (r != 0) {
apk_error("%s: %s", argv[i], apk_error_str(r));
goto err;
}
}
apk_dep_from_pkg(&dep, &db, pkg);
} else {
r = apk_dep_from_blob(&dep, &db, APK_BLOB_STR(argv[i]));
......
......@@ -134,6 +134,7 @@ int apk_db_open(struct apk_database *db, const char *root, unsigned int flags);
int apk_db_write_config(struct apk_database *db);
void apk_db_close(struct apk_database *db);
int apk_db_cache_active(struct apk_database *db);
int apk_db_permanent(struct apk_database *db);
struct apk_package *apk_db_pkg_add(struct apk_database *db, struct apk_package *pkg);
struct apk_package *apk_db_get_pkg(struct apk_database *db, struct apk_checksum *csum);
......
......@@ -941,6 +941,17 @@ int apk_db_cache_active(struct apk_database *db)
return db->cache_dir != apk_static_cache_dir;
}
int apk_db_permanent(struct apk_database *db)
{
struct stat st;
if (fstat(db->root_fd, &st) != 0)
return 0;
if (major(st.st_dev) == 0)
return 0;
return 1;
}
struct apk_package *apk_db_get_pkg(struct apk_database *db,
struct apk_checksum *csum)
{
......
......@@ -181,7 +181,7 @@ void apk_dep_from_pkg(struct apk_dependency *dep, struct apk_database *db,
struct apk_package *pkg)
{
*dep = (struct apk_dependency) {
.name = apk_db_get_name(db, APK_BLOB_STR(pkg->name->name)),
.name = pkg->name,
.version = pkg->version,
.result_mask = APK_VERSION_EQUAL,
};
......@@ -735,7 +735,7 @@ int apk_pkg_read(struct apk_database *db, const char *file,
ctx.pkg = apk_db_pkg_add(db, ctx.pkg);
if (pkg != NULL)
*pkg = ctx.pkg;
r = 0;
return 0;
err:
apk_pkg_free(ctx.pkg);
return r;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment