add: add support to install packages not in a repository

cute-signatures
Timo Teras 2008-11-28 13:34:40 +02:00
parent 545a915faf
commit 5ea81ca564
5 changed files with 37 additions and 15 deletions

View File

@ -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;
}

View File

@ -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);

View File

@ -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;

View File

@ -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;

View File

@ -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: