add: add support to install packages not in a repository
parent
545a915faf
commit
5ea81ca564
26
src/add.c
26
src/add.c
|
@ -22,14 +22,32 @@ static int add_main(int argc, char **argv)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
for (i = 0; i < argc; i++) {
|
for (i = 0; i < argc; i++) {
|
||||||
struct apk_dependency dep = {
|
struct apk_dependency dep;
|
||||||
.name = apk_db_get_name(&db, APK_BLOB_STR(argv[i])),
|
|
||||||
};
|
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_deps_add(&db.world, &dep);
|
||||||
}
|
}
|
||||||
apk_db_recalculate_and_commit(&db);
|
apk_db_recalculate_and_commit(&db);
|
||||||
|
err:
|
||||||
apk_db_close(&db);
|
apk_db_close(&db);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -93,7 +93,7 @@ int apk_db_create(const char *root);
|
||||||
int apk_db_open(struct apk_database *db, const char *root);
|
int apk_db_open(struct apk_database *db, const char *root);
|
||||||
void apk_db_close(struct apk_database *db);
|
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);
|
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);
|
void apk_db_index_write(struct apk_database *db, int fd);
|
||||||
|
|
|
@ -55,6 +55,7 @@ struct apk_package {
|
||||||
char *url, *description, *license;
|
char *url, *description, *license;
|
||||||
struct apk_dependency_array *depends;
|
struct apk_dependency_array *depends;
|
||||||
unsigned int installed_size, size;
|
unsigned int installed_size, size;
|
||||||
|
char *filename;
|
||||||
|
|
||||||
/* for installed packages only */
|
/* for installed packages only */
|
||||||
struct list_head installed_pkgs_list;
|
struct list_head installed_pkgs_list;
|
||||||
|
|
|
@ -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)));
|
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;
|
struct apk_package *info;
|
||||||
|
|
||||||
info = apk_pkg_read(db, file);
|
info = apk_pkg_read(db, file);
|
||||||
if (info == NULL)
|
if (info != NULL)
|
||||||
return FALSE;
|
apk_db_pkg_add(db, info);
|
||||||
|
return info;
|
||||||
apk_db_pkg_add(db, info);
|
|
||||||
return TRUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int write_index_entry(apk_hash_item item, void *ctx)
|
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 */
|
/* Install the new stuff */
|
||||||
snprintf(file, sizeof(file),
|
if (newpkg->filename == NULL) {
|
||||||
"%s/%s-%s.apk",
|
snprintf(file, sizeof(file),
|
||||||
db->repos[0].url, newpkg->name->name, newpkg->version);
|
"%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) {
|
if (fd < 0) {
|
||||||
apk_error("%s: %s", file, strerror(errno));
|
apk_error("%s: %s", file, strerror(errno));
|
||||||
return errno;
|
return errno;
|
||||||
|
|
|
@ -373,6 +373,7 @@ struct apk_package *apk_pkg_read(struct apk_database *db, const char *file)
|
||||||
};
|
};
|
||||||
apk_deps_add(&ctx.pkg->depends, &dep);
|
apk_deps_add(&ctx.pkg->depends, &dep);
|
||||||
}
|
}
|
||||||
|
ctx.pkg->filename = strdup(file);
|
||||||
|
|
||||||
return ctx.pkg;
|
return ctx.pkg;
|
||||||
err:
|
err:
|
||||||
|
|
Loading…
Reference in New Issue