PAKFIRE_PKG_BUILD_HOST,
PAKFIRE_PKG_BUILD_ID,
PAKFIRE_PKG_BUILD_TIME,
+ PAKFIRE_PKG_BUILD_ARCHES,
PAKFIRE_PKG_SOURCE_PKG,
PAKFIRE_PKG_SOURCE_NAME,
PAKFIRE_PKG_SOURCE_EVR,
unsigned int pakfire_package_id(struct pakfire_package* pkg);
+void pakfire_package_unset(struct pakfire_package* pkg,
+ const enum pakfire_package_key key);
+
// String
const char* pakfire_package_get_string(struct pakfire_package* pkg,
const enum pakfire_package_key key);
int pakfire_package_set_string(struct pakfire_package* pkg,
const enum pakfire_package_key key, const char* value);
+// String Arrays
+const char** pakfire_package_get_strings(struct pakfire_package* pkg,
+ const enum pakfire_package_key key);
+int pakfire_package_set_strings(struct pakfire_package* pkg,
+ const enum pakfire_package_key key, const char** values);
+int pakfire_package_add_string(struct pakfire_package* pkg,
+ const enum pakfire_package_key key, const char* value);
+
// UUID
int pakfire_package_get_uuid(struct pakfire_package* pkg,
const enum pakfire_package_key key, uuid_t uuid);
int pakfire_package_create_from_solvable(struct pakfire_package** package,
struct pakfire* pakfire, Id id);
+int pakfire_package_set_strings_from_string(struct pakfire_package* pkg,
+ const enum pakfire_package_key key, const char* value);
+
int pakfire_package_is_source(struct pakfire_package* pkg);
char* pakfire_package_join_evr(const char* e, const char* v, const char* r);
return pakfire_cache_path(pkg->pakfire, pkg->cache_path, "%s/%s", uuid, filename);
}
+PAKFIRE_EXPORT void pakfire_package_unset(struct pakfire_package* pkg,
+ const enum pakfire_package_key key) {
+ Id id = ID_NULL;
+
+ Solvable* s = get_solvable(pkg);
+
+ switch (key) {
+ // Some keys cannot be unset
+ case PAKFIRE_PKG_NAME:
+ case PAKFIRE_PKG_EVR:
+ case PAKFIRE_PKG_ARCH:
+ return;
+
+ case PAKFIRE_PKG_NEVRA:
+ break;
+
+ case PAKFIRE_PKG_UUID:
+ id = SOLVABLE_PKGID;
+ break;
+
+ case PAKFIRE_PKG_SUMMARY:
+ id = SOLVABLE_SUMMARY;
+ break;
+
+ case PAKFIRE_PKG_DESCRIPTION:
+ id = SOLVABLE_DESCRIPTION;
+ break;
+
+ case PAKFIRE_PKG_LICENSE:
+ id = SOLVABLE_LICENSE;
+ break;
+
+ case PAKFIRE_PKG_URL:
+ id = SOLVABLE_URL;
+ break;
+
+ case PAKFIRE_PKG_GROUPS:
+ id = SOLVABLE_GROUP;
+ break;
+
+ case PAKFIRE_PKG_VENDOR:
+ id = SOLVABLE_VENDOR;
+ break;
+
+ case PAKFIRE_PKG_DISTRO:
+ id = SOLVABLE_DISTRIBUTION;
+ break;
+
+ case PAKFIRE_PKG_PACKAGER:
+ id = SOLVABLE_PACKAGER;
+ break;
+
+ case PAKFIRE_PKG_PATH:
+ id = SOLVABLE_MEDIADIR;
+
+ // Unset the filename, too
+ pakfire_package_unset(pkg, PAKFIRE_PKG_FILENAME);
+
+ // Invalidate the cache
+ *pkg->path = '\0';
+ break;
+
+ case PAKFIRE_PKG_FILENAME:
+ id = SOLVABLE_MEDIAFILE;
+ break;
+
+ case PAKFIRE_PKG_CACHE_PATH:
+ *pkg->cache_path = '\0';
+ break;
+
+ case PAKFIRE_PKG_BUILD_HOST:
+ id = SOLVABLE_BUILDHOST;
+ break;
+
+ case PAKFIRE_PKG_BUILD_ID:
+ id = SOLVABLE_BUILDVERSION;
+ break;
+
+ case PAKFIRE_PKG_BUILD_TIME:
+ id = SOLVABLE_BUILDTIME;
+ break;
+
+ case PAKFIRE_PKG_BUILD_ARCHES:
+ id = SOLVABLE_BUILDFLAVOR;
+ break;
+
+ case PAKFIRE_PKG_SOURCE_PKG:
+ pakfire_package_unset(pkg, PAKFIRE_PKG_SOURCE_NAME);
+ pakfire_package_unset(pkg, PAKFIRE_PKG_SOURCE_EVR);
+ pakfire_package_unset(pkg, PAKFIRE_PKG_SOURCE_ARCH);
+
+ // Invalidate cache
+ *pkg->source_nevra = '\0';
+ break;
+
+ case PAKFIRE_PKG_SOURCE_NAME:
+ id = SOLVABLE_SOURCENAME;
+ break;
+
+ case PAKFIRE_PKG_SOURCE_EVR:
+ id = SOLVABLE_SOURCEEVR;
+ break;
+
+ case PAKFIRE_PKG_SOURCE_ARCH:
+ id = SOLVABLE_SOURCEARCH;
+ break;
+
+ case PAKFIRE_PKG_DOWNLOADSIZE:
+ id = SOLVABLE_DOWNLOADSIZE;
+ break;
+
+ case PAKFIRE_PKG_INSTALLSIZE:
+ id = SOLVABLE_INSTALLSIZE;
+ break;
+
+ case PAKFIRE_PKG_INSTALLTIME:
+ id = SOLVABLE_INSTALLTIME;
+ break;
+
+ // Cannot unset dependencies here
+ case PAKFIRE_PKG_PROVIDES:
+ case PAKFIRE_PKG_PREREQUIRES:
+ case PAKFIRE_PKG_REQUIRES:
+ case PAKFIRE_PKG_CONFLICTS:
+ case PAKFIRE_PKG_OBSOLETES:
+ case PAKFIRE_PKG_RECOMMENDS:
+ case PAKFIRE_PKG_SUGGESTS:
+ case PAKFIRE_PKG_SUPPLEMENTS:
+ case PAKFIRE_PKG_ENHANCES:
+ return;
+
+ case PAKFIRE_PKG_DBID:
+ return;
+ }
+
+ // Unset any values
+ solvable_unset(s, id);
+}
+
+PAKFIRE_EXPORT const char** pakfire_package_get_strings(
+ struct pakfire_package* pkg, const enum pakfire_package_key key) {
+ const char** ret = NULL;
+ Queue strings;
+ Id id = ID_NULL;
+
+ pakfire_package_internalize_repo(pkg);
+
+ Pool* pool = pakfire_get_solv_pool(pkg->pakfire);
+ Solvable* s = get_solvable(pkg);
+
+ switch (key) {
+ case PAKFIRE_PKG_BUILD_ARCHES:
+ id = SOLVABLE_BUILDFLAVOR;
+ break;
+
+ default:
+ errno = EINVAL;
+ return NULL;
+ }
+
+ // Setup a queue
+ queue_init(&strings);
+
+ // Fetch the strings
+ solvable_lookup_idarray(s, id, &strings);
+
+ if (strings.count) {
+ // Allocate an array
+ ret = calloc(strings.count + 1, sizeof(*ret));
+ if (!ret)
+ goto ERROR;
+
+ // Fetch the strings
+ for (int i = 0; i < strings.count; i++)
+ ret[i] = pool_id2str(pool, strings.elements[i]);
+ }
+
+ERROR:
+ // Free the queue
+ queue_free(&strings);
+
+ return ret;
+}
+
+PAKFIRE_EXPORT int pakfire_package_set_strings(struct pakfire_package* pkg,
+ const enum pakfire_package_key key, const char** values) {
+ int r;
+
+ // Drop any previous values
+ pakfire_package_unset(pkg, key);
+
+ // End without error if values is empty
+ if (!values)
+ return 0;
+
+ // Add all new values
+ for (const char** value = values; *value; value++) {
+ r = pakfire_package_add_string(pkg, key, *value);
+ if (r)
+ return r;
+ }
+
+ return 0;
+}
+
+int pakfire_package_set_strings_from_string(struct pakfire_package* pkg,
+ const enum pakfire_package_key key, const char* value) {
+ char* buffer = NULL;
+ char* p = NULL;
+ int r;
+
+ // Drop any previous values
+ pakfire_package_unset(pkg, key);
+
+ // End without error if value is empty
+ if (!value || !*value)
+ return 0;
+
+ // Copy the string to the heap to change it
+ buffer = strdup(value);
+ if (!buffer) {
+ r = -errno;
+ goto ERROR;
+ }
+
+ // Split the string
+ char* s = strtok_r(buffer, " ", &p);
+
+ // Add each part individually
+ while (s) {
+ r = pakfire_package_add_string(pkg, key, s);
+ if (r)
+ goto ERROR;
+
+ // Move on to the next part
+ s = strtok_r(NULL, " ", &p);
+ }
+
+ERROR:
+ if (buffer)
+ free(buffer);
+
+ return r;
+}
+
PAKFIRE_EXPORT const char* pakfire_package_get_string(
struct pakfire_package* pkg, const enum pakfire_package_key key) {
const char* ret = NULL;
id = SOLVABLE_SOURCEARCH;
break;
+ // Compat which splits a string and stores it as an array
+ case PAKFIRE_PKG_BUILD_ARCHES:
+ return pakfire_package_set_strings_from_string(pkg, key, value);
+
default:
break;
}
return 0;
}
+PAKFIRE_EXPORT int pakfire_package_add_string(struct pakfire_package* pkg,
+ const enum pakfire_package_key key, const char* value) {
+ Id key_id = ID_NULL;
+ Id value_id = ID_NULL;
+
+ Pool* pool = pakfire_get_solv_pool(pkg->pakfire);
+ Solvable* s = get_solvable(pkg);
+
+ switch (key) {
+ case PAKFIRE_PKG_BUILD_ARCHES:
+ key_id = SOLVABLE_BUILDFLAVOR;
+ value_id = pool_str2id(pool, value, 1);
+ break;
+
+ default:
+ errno = EINVAL;
+ return 1;
+ }
+
+ // Append the string to the ID array
+ solvable_add_idarray(s, key_id, value_id);
+
+ // Mark the package as changed
+ pakfire_package_has_changed(pkg);
+
+ return 0;
+}
+
PAKFIRE_EXPORT int pakfire_package_get_uuid(struct pakfire_package* pkg,
const enum pakfire_package_key key, uuid_t uuid) {
const char* buffer = NULL;
if (build_id)
pakfire_package_dump_add_line(&string, _("Build ID"), build_id);
+ // Build Arches
+ const char** build_arches = pakfire_package_get_strings(pkg, PAKFIRE_PKG_BUILD_ARCHES);
+ if (build_arches) {
+ for (const char** build_arch = build_arches; *build_arch; build_arch++)
+ pakfire_package_dump_add_line(&string, _("Build Arch"), *build_arch);
+
+ free(build_arches);
+ }
+
enum pakfire_digest_types digest_type = PAKFIRE_DIGEST_UNDEFINED;
size_t digest_length = 0;
return 1;
// Add dependencies
- int r = pakfire_json_add_string_array(pkg->pakfire, json, name, dependencies);
+ int r = pakfire_json_add_string_array(pkg->pakfire, json,
+ name, (const char**)dependencies);
if (r)
goto ERROR;
goto ERROR;
}
+ // Write build arches
+ const char** build_arches = pakfire_package_get_strings(pkg, PAKFIRE_PKG_BUILD_ARCHES);
+ if (build_arches) {
+ r = pakfire_json_add_string_array(pkg->pakfire, object, "arches", build_arches);
+ free(build_arches);
+
+ if (r)
+ goto ERROR;
+ }
+
// Source package name
const char* name = pakfire_package_get_string(pkg, PAKFIRE_PKG_SOURCE_NAME);
if (name) {