]> git.ipfire.org Git - pakfire.git/commitdiff
packages: Move pakfire_package_get/set_path into string function
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 26 Oct 2022 16:40:56 +0000 (16:40 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 26 Oct 2022 16:40:56 +0000 (16:40 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/archive.c
src/libpakfire/include/pakfire/package.h
src/libpakfire/package.c
src/libpakfire/repo.c
src/libpakfire/transaction.c

index cbcabb0ba6a944ec05f101c01e9632c7e52b7c47..c1c5e9530d29f32cc1e5a1556baeef9cb479f40d 100644 (file)
@@ -1073,7 +1073,7 @@ static int pakfire_archive_make_package_from_json(struct pakfire_archive* archiv
 #endif
 
        // Set path
-       pakfire_package_set_path(pkg, archive->path);
+       pakfire_package_set_string(pkg, PAKFIRE_PKG_PATH, archive->path);
 
        // Set digest
        switch (PAKFIRE_ARCHIVE_CHECKSUM) {
@@ -1375,7 +1375,7 @@ static int pakfire_archive_make_legacy_package(struct pakfire_archive* archive,
 #endif
 
        // Set path
-       pakfire_package_set_path(pkg, archive->path);
+       pakfire_package_set_string(pkg, PAKFIRE_PKG_PATH, archive->path);
 
        // Set UUID
        r = pakfire_archive_package_set_string(archive, pkg,
index bf633d0faa4e6dbb0f3dfb577cbd59445e9ffde1..71086d3bf081124ec46cc40a6cbd8748e529868d 100644 (file)
@@ -48,6 +48,7 @@ enum pakfire_package_key {
        PAKFIRE_PKG_VENDOR,
        PAKFIRE_PKG_DISTRO,
        PAKFIRE_PKG_MAINTAINER,
+       PAKFIRE_PKG_PATH,
        PAKFIRE_PKG_FILENAME,
        PAKFIRE_PKG_DOWNLOADSIZE,
        PAKFIRE_PKG_INSTALLSIZE,
@@ -94,8 +95,6 @@ const unsigned char* pakfire_package_get_digest(struct pakfire_package* pkg,
        enum pakfire_digest_types* type, size_t* length);
 int pakfire_package_set_digest(struct pakfire_package* pkg,
        enum pakfire_digest_types type, const unsigned char* digest, const size_t length);
-const char* pakfire_package_get_path(struct pakfire_package* pkg);
-void pakfire_package_set_path(struct pakfire_package* pkg, const char* path);
 size_t pakfire_package_get_size(struct pakfire_package* pkg);
 
 char** pakfire_package_get_provides(struct pakfire_package* pkg);
index 812a43e231d11bb1d09df3ae2f87ac8d66cf1326..c24aeadd756342840db886718c81b7a8dc75896b 100644 (file)
@@ -323,6 +323,23 @@ static const char* pakfire_package_make_filename(struct pakfire_package* pkg) {
        return pkg->filename;
 }
 
+static int pakfire_package_make_cache_path(struct pakfire_package* pkg) {
+       const char* filename = pakfire_package_get_string(pkg, PAKFIRE_PKG_FILENAME);
+
+       enum pakfire_digest_types digest_type = PAKFIRE_DIGEST_UNDEFINED;
+       size_t digest_length = 0;
+
+       // Fetch the digest
+       const unsigned char* digest = pakfire_package_get_digest(pkg,
+               &digest_type, &digest_length);
+
+       if (digest && digest_length >= 4)
+               return pakfire_cache_path(pkg->pakfire, pkg->path,
+                       "%02x/%02x/%02x/%02x/%s", digest[0], digest[1], digest[2], digest[3], filename);
+
+       return pakfire_cache_path(pkg->pakfire, pkg->path, "%s", filename);
+}
+
 PAKFIRE_EXPORT const char* pakfire_package_get_string(
                struct pakfire_package* pkg, const enum pakfire_package_key key) {
        const char* ret = NULL;
@@ -388,6 +405,24 @@ PAKFIRE_EXPORT const char* pakfire_package_get_string(
                        ret = solvable_lookup_str(s, SOLVABLE_PACKAGER);
                        break;
 
+               case PAKFIRE_PKG_PATH:
+                       if (!*pkg->path) {
+                               const char* base = solvable_lookup_str(s, SOLVABLE_MEDIABASE);
+                               if (base) {
+                                       const char* filename = pakfire_package_get_string(pkg, PAKFIRE_PKG_FILENAME);
+                                       if (!filename)
+                                               return NULL;
+
+                                       pakfire_string_format(pkg->path, "%s/%s", base, filename);
+                               } else {
+                                       r = pakfire_package_make_cache_path(pkg);
+                                       if (r)
+                                               return NULL;
+                               }
+                       }
+
+                       return pkg->path;
+
                case PAKFIRE_PKG_FILENAME:
                        ret = solvable_lookup_str(s, SOLVABLE_MEDIAFILE);
 
@@ -448,6 +483,9 @@ PAKFIRE_EXPORT int pakfire_package_set_string(
        Pool* pool = pakfire_get_solv_pool(pkg->pakfire);
        Solvable* s = get_solvable(pkg);
 
+       const char* basename = NULL;
+       const char* dirname = NULL;
+
        switch (key) {
                // Do not allow to change name, evr, or arch
                case PAKFIRE_PKG_NAME:
@@ -515,6 +553,30 @@ PAKFIRE_EXPORT int pakfire_package_set_string(
                        id = SOLVABLE_PACKAGER;
                        break;
 
+               case PAKFIRE_PKG_PATH:
+                       if (value) {
+                               basename = pakfire_basename(value);
+                               dirname  = pakfire_dirname(value);
+                       }
+
+                       if (basename)
+                               solvable_set_str(s, SOLVABLE_MEDIAFILE, basename);
+                       else
+                               solvable_unset(s, SOLVABLE_MEDIAFILE);
+
+                       if (dirname)
+                               solvable_set_str(s, SOLVABLE_MEDIABASE, dirname);
+                       else
+                               solvable_unset(s, SOLVABLE_MEDIABASE);
+
+                       // Cache the path
+                       pakfire_string_set(pkg->path, value);
+
+                       // Mark the package as changed
+                       pakfire_package_has_changed(pkg);
+
+                       return 0;
+
                case PAKFIRE_PKG_FILENAME:
                        id = SOLVABLE_MEDIAFILE;
                        break;
@@ -761,57 +823,6 @@ ERROR:
        return r;
 }
 
-static int pakfire_package_make_cache_path(struct pakfire_package* pkg) {
-       const char* filename = pakfire_package_get_string(pkg, PAKFIRE_PKG_FILENAME);
-
-       enum pakfire_digest_types digest_type = PAKFIRE_DIGEST_UNDEFINED;
-       size_t digest_length = 0;
-
-       // Fetch the digest
-       const unsigned char* digest = pakfire_package_get_digest(pkg,
-               &digest_type, &digest_length);
-
-       if (digest && digest_length >= 4)
-               return pakfire_cache_path(pkg->pakfire, pkg->path,
-                       "%02x/%02x/%02x/%02x/%s", digest[0], digest[1], digest[2], digest[3], filename);
-
-       return pakfire_cache_path(pkg->pakfire, pkg->path, "%s", filename);
-}
-
-PAKFIRE_EXPORT const char* pakfire_package_get_path(struct pakfire_package* pkg) {
-       int r;
-
-       if (!*pkg->path) {
-               const char* base = pakfire_package_get_string(pkg, SOLVABLE_MEDIABASE);
-               if (base) {
-                       const char* filename = pakfire_package_get_string(pkg, PAKFIRE_PKG_FILENAME);
-                       if (!filename)
-                               return NULL;
-
-                       pakfire_string_format(pkg->path, "%s/%s", base, filename);
-               } else {
-                       r = pakfire_package_make_cache_path(pkg);
-                       if (r)
-                               return NULL;
-               }
-       }
-
-       return pkg->path;
-}
-
-PAKFIRE_EXPORT void pakfire_package_set_path(struct pakfire_package* pkg, const char* path) {
-       const char* basename = pakfire_basename(path);
-       const char* dirname  = pakfire_dirname(path);
-
-       if (basename)
-               pakfire_package_set_string(pkg, SOLVABLE_MEDIAFILE, basename);
-
-       if (dirname)
-               pakfire_package_set_string(pkg, SOLVABLE_MEDIABASE, dirname);
-
-       pakfire_string_set(pkg->path, path);
-}
-
 int pakfire_package_is_installed(struct pakfire_package* pkg) {
        Pool* pool = pakfire_get_solv_pool(pkg->pakfire);
        Solvable* s = get_solvable(pkg);
@@ -1305,7 +1316,7 @@ PAKFIRE_EXPORT struct pakfire_archive* pakfire_package_get_archive(struct pakfir
        struct pakfire_archive* archive = NULL;
 
        // Otherwise open the archive from the cache
-       const char* path = pakfire_package_get_path(pkg);
+       const char* path = pakfire_package_get_string(pkg, PAKFIRE_PKG_PATH);
        if (!path)
                return NULL;
 
index 438d119405f20ffebc5f4c41f4997fcd7ffcfcbe..dfbf158cca17c87dd77b3200fcfd25b1c6fd989c 100644 (file)
@@ -1026,7 +1026,7 @@ static int pakfire_repo_delete_all_packages(
                        return 1;
 
                const char* nevra = pakfire_package_get_string(pkg, PAKFIRE_PKG_NEVRA);
-               const char* path = pakfire_package_get_path(pkg);
+               const char* path = pakfire_package_get_string(pkg, PAKFIRE_PKG_PATH);
 
                // If prefix is set, skip anything that doesn't match
                if (prefix && !pakfire_string_startswith(path, prefix))
@@ -1498,7 +1498,7 @@ PAKFIRE_EXPORT int pakfire_repo_compose(struct pakfire* pakfire, const char* pat
                        const char* repo_path = pakfire_path_relpath(path, destination_path);
 
                        // Update package location relative to the repository directory
-                       pakfire_package_set_path(package, repo_path);
+                       pakfire_package_set_string(package, PAKFIRE_PKG_PATH, repo_path);
 
 OUT:
                        if (archive) {
index 33aebd36a44f7f34af6f164d6c77e5e76e9a0a5d..73a61e41da60f3eedd8cd1be5649f98b4342de5f 100644 (file)
@@ -1149,7 +1149,7 @@ static int pakfire_transaction_download_package(struct pakfire_transaction* tran
                goto ERROR;
 
        // Where to store the package?
-       const char* path = pakfire_package_get_path(pkg);
+       const char* path = pakfire_package_get_string(pkg, PAKFIRE_PKG_PATH);
        if (!path) {
                ERROR(transaction->pakfire, "Could not retrieve package path for %s: %m\n", nevra);
                goto ERROR;
@@ -1200,7 +1200,7 @@ static int pakfire_transaction_package_needs_download(
        if (pakfire_package_is_installed(pkg))
                return 0;
 
-       const char* path = pakfire_package_get_path(pkg);
+       const char* path = pakfire_package_get_string(pkg, PAKFIRE_PKG_PATH);
 
        // Does the file exist?
        int r = access(path, R_OK);