summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimo Teras <timo.teras@iki.fi>2009-07-22 20:47:21 +0300
committerTimo Teras <timo.teras@iki.fi>2009-07-22 20:47:21 +0300
commit718ef3079ea18fcb588264d26e3316628ad18ba0 (patch)
tree7a945f9ad7510096854bb2f599271b7a73aafa95
parent9b77c053e8fd03348ed04ba09ceaaf7ba99ca6f6 (diff)
downloadapk-tools-718ef3079ea18fcb588264d26e3316628ad18ba0.tar.gz
apk-tools-718ef3079ea18fcb588264d26e3316628ad18ba0.tar.bz2
apk-tools-718ef3079ea18fcb588264d26e3316628ad18ba0.tar.xz
apk-tools-718ef3079ea18fcb588264d26e3316628ad18ba0.zip
add: fixes to installing non-repository package
make sure cache is enabled on non-permanent rootfs setups. some optimizations and fixes too.
-rw-r--r--src/add.c16
-rw-r--r--src/apk_database.h1
-rw-r--r--src/database.c11
-rw-r--r--src/package.c4
4 files changed, 27 insertions, 5 deletions
diff --git a/src/add.c b/src/add.c
index 4dd93e9..0b402fe 100644
--- a/src/add.c
+++ b/src/add.c
@@ -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]));
diff --git a/src/apk_database.h b/src/apk_database.h
index 0edf4f2..46e6152 100644
--- a/src/apk_database.h
+++ b/src/apk_database.h
@@ -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);
diff --git a/src/database.c b/src/database.c
index b27df99..e171ca9 100644
--- a/src/database.c
+++ b/src/database.c
@@ -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)
{
diff --git a/src/package.c b/src/package.c
index 4f6262e..0ef1d59 100644
--- a/src/package.c
+++ b/src/package.c
@@ -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;