add: support for forced versions

Support version numbers specified with packages. For example:

 apk add 'busybox<1.14'
 apk add 'squid=>3.0'
cute-signatures
Natanael Copa 2009-06-16 09:59:21 +00:00
parent d8b1b851c7
commit 20a1217e86
5 changed files with 61 additions and 16 deletions

View File

@ -122,11 +122,7 @@ static int add_main(void *ctx, int argc, char **argv)
md5_str(virtpkg->name->name, virtpkg->csum);
virtpkg->version = strdup("0");
virtpkg->description = strdup("virtual meta package");
virtdep = (struct apk_dependency) {
.name = virtpkg->name,
.version = virtpkg->version,
.result_mask = APK_VERSION_EQUAL,
};
virtdep = apk_dep_from_pkg(&db, virtpkg);
virtdep.name->flags |= APK_NAME_TOPLEVEL | APK_NAME_VIRTUAL;
virtpkg = apk_db_pkg_add(&db, virtpkg);
}
@ -143,17 +139,10 @@ static int add_main(void *ctx, int argc, char **argv)
goto err;
}
dep = (struct apk_dependency) {
.name = apk_db_get_name(&db, APK_BLOB_STR(pkg->name->name)),
.version = pkg->version,
.result_mask = APK_VERSION_EQUAL,
};
} else {
dep = (struct apk_dependency) {
.name = apk_db_get_name(&db, APK_BLOB_STR(argv[i])),
.result_mask = APK_DEPMASK_REQUIRE,
};
}
dep = apk_dep_from_pkg(&db, pkg);
} else
dep = apk_dep_from_str(&db, argv[i]);
if (virtpkg) {
apk_deps_add(&virtpkg->depends, &dep);
} else {

View File

@ -94,4 +94,8 @@ int apk_pkg_run_script(struct apk_package *pkg, int root_fd,
struct apk_package *apk_pkg_parse_index_entry(struct apk_database *db, apk_blob_t entry);
int apk_pkg_write_index_entry(struct apk_package *pkg, struct apk_ostream *os);
struct apk_dependency apk_dep_from_str(struct apk_database *db,
char *str);
struct apk_dependency apk_dep_from_pkg(struct apk_database *db,
struct apk_package *pkg);
#endif

View File

@ -19,6 +19,7 @@
#define APK_VERSION_GREATER 4
const char *apk_version_op_string(int result_mask);
int apk_version_result_mask(const char *str);
int apk_version_validate(apk_blob_t ver);
int apk_version_compare(apk_blob_t a, apk_blob_t b);

View File

@ -663,3 +663,36 @@ int apk_pkg_write_index_entry(struct apk_package *info,
return n;
}
struct apk_dependency apk_dep_from_str(struct apk_database *db,
char *str)
{
apk_blob_t name = APK_BLOB_STR(str);
char *v = str;
int mask = APK_DEPMASK_REQUIRE;
v = strpbrk(str, "<>=");
if (v != NULL) {
name.len = v - str;
mask = apk_version_result_mask(v++);
if (*v == '=')
v++;
}
printf("DEBUG: result_mask = %x\n", mask);
return (struct apk_dependency) {
.name = apk_db_get_name(db, name),
.version = v,
.result_mask = mask,
};
}
struct apk_dependency apk_dep_from_pkg(struct apk_database *db,
struct apk_package *pkg)
{
return (struct apk_dependency) {
.name = apk_db_get_name(db, APK_BLOB_STR(pkg->name->name)),
.version = pkg->version,
.result_mask = APK_VERSION_EQUAL,
};
}

View File

@ -146,6 +146,24 @@ const char *apk_version_op_string(int mask)
}
}
int apk_version_result_mask(const char *str)
{
int r = 0;
switch (*str) {
case '<':
r = APK_VERSION_LESS;
str++;
break;
case '>':
r = APK_VERSION_GREATER;
str++;
break;
}
if (*str == '=')
r |= APK_VERSION_EQUAL;
return r;
}
int apk_version_validate(apk_blob_t ver)
{
int t = TOKEN_DIGIT;