]> git.ipfire.org Git - pakfire.git/commitdiff
libpakfire: Move package caching into Package
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 19 Jan 2018 00:43:51 +0000 (01:43 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 19 Jan 2018 00:43:51 +0000 (01:43 +0100)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/_pakfire/package.c
src/libpakfire/cache.c
src/libpakfire/include/pakfire/cache.h
src/libpakfire/include/pakfire/packagecache.h [deleted file]
src/libpakfire/libpakfire.sym
src/libpakfire/package.c
src/libpakfire/packagecache.c [deleted file]
src/libpakfire/step.c

index 01fb04c6b159b7d8948a9d6b362a09cf16e9241d..b64a95a035fb10932887f3168aae83d6cf8a4623 100644 (file)
@@ -280,7 +280,6 @@ pkginclude_HEADERS += \
        src/libpakfire/include/pakfire/key.h \
        src/libpakfire/include/pakfire/logging.h \
        src/libpakfire/include/pakfire/package.h \
-       src/libpakfire/include/pakfire/packagecache.h \
        src/libpakfire/include/pakfire/packagelist.h \
        src/libpakfire/include/pakfire/pakfire.h \
        src/libpakfire/include/pakfire/pool.h \
index 5d7530b4dcb9f9d7dd02d0472a3f46aed91134c2..9468a1fba91d44d90935ff07d04bdc7a05f52e04 100644 (file)
@@ -444,14 +444,6 @@ static PyObject* Package_get_cache_path(PackageObject* self) {
        return ret;
 }
 
-static PyObject* Package_get_cache_full_path(PackageObject* self) {
-       char* cache_path = pakfire_package_get_cache_full_path(self->package);
-       PyObject* ret = PyUnicode_FromString(cache_path);
-       pakfire_free(cache_path);
-
-       return ret;
-}
-
 static PyObject* Package_get_repo(PackageObject* self) {
        PakfireRepo repo = pakfire_package_get_repo(self->package);
        if (!repo)
@@ -1015,13 +1007,6 @@ static struct PyGetSetDef Package_getsetters[] = {
                NULL,
                NULL
        },
-       {
-               "cache_full_path",
-               (getter)Package_get_cache_full_path,
-               NULL,
-               NULL,
-               NULL
-       },
 
        // Dependencies
        {
index 6c7a744b0ac8498fd2067b8bc982b050fc1a3d28..9b6f540bec6175e5747c204aa3728619504cbe16 100644 (file)
@@ -74,30 +74,6 @@ PAKFIRE_EXPORT int pakfire_cache_has_file(PakfireCache cache, const char* filena
        return (r == 0);
 }
 
-PAKFIRE_EXPORT char* pakfire_cache_get_package_path(PakfireCache cache, PakfirePackage pkg) {
-       char buffer[STRING_SIZE] = "";
-
-       const char* filename = pakfire_package_get_filename(pkg);
-       const char* checksum = pakfire_package_get_checksum(pkg);
-
-       if (strlen(checksum) < 3)
-               return NULL;
-
-       snprintf(buffer, sizeof(buffer), "%c%c/%s/%s", checksum[0], checksum[1],
-               checksum + 2, filename);
-
-       return pakfire_strdup(buffer);
-}
-
-PAKFIRE_EXPORT int pakfire_cache_has_package(PakfireCache cache, PakfirePackage pkg) {
-       char* filename = pakfire_cache_get_package_path(cache, pkg);
-
-       int r = pakfire_cache_has_file(cache, filename);
-       pakfire_free(filename);
-
-       return r;
-}
-
 PAKFIRE_EXPORT int pakfire_cache_age(PakfireCache cache, const char* filename) {
        struct stat buf;
        int r = pakfire_cache_stat(cache, filename, &buf);
index c302c562033a49482b4a9822982cf4461f9098dc..78d4c59021a41f5efad5ceb45e365166bcd2b45e 100644 (file)
@@ -32,8 +32,6 @@ const char* pakfire_cache_get_path(PakfireCache cache);
 char* pakfire_cache_get_full_path(PakfireCache cache, const char* path);
 
 int pakfire_cache_has_file(PakfireCache cache, const char* filename);
-char* pakfire_cache_get_package_path(PakfireCache cache, PakfirePackage pkg);
-int pakfire_cache_has_package(PakfireCache cache, PakfirePackage pkg);
 int pakfire_cache_age(PakfireCache cache, const char* filename);
 
 FILE* pakfire_cache_open(PakfireCache cache, const char* filename, const char* flags);
diff --git a/src/libpakfire/include/pakfire/packagecache.h b/src/libpakfire/include/pakfire/packagecache.h
deleted file mode 100644 (file)
index 9c07273..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-/*#############################################################################
-#                                                                             #
-# Pakfire - The IPFire package management system                              #
-# Copyright (C) 2013 Pakfire development team                                 #
-#                                                                             #
-# This program is free software: you can redistribute it and/or modify        #
-# it under the terms of the GNU General Public License as published by        #
-# the Free Software Foundation, either version 3 of the License, or           #
-# (at your option) any later version.                                         #
-#                                                                             #
-# This program is distributed in the hope that it will be useful,             #
-# but WITHOUT ANY WARRANTY; without even the implied warranty of              #
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #
-# GNU General Public License for more details.                                #
-#                                                                             #
-# You should have received a copy of the GNU General Public License           #
-# along with this program.  If not, see <http://www.gnu.org/licenses/>.       #
-#                                                                             #
-#############################################################################*/
-
-#ifndef PAKFIRE_PACKAGECACHE_H
-#define PAKFIRE_PACKAGECACHE_H
-
-#include <pakfire/types.h>
-
-PakfirePackageCache pakfire_packagecache_create(PakfirePool pool, const char* path);
-void pakfire_packagecache_free(PakfirePackageCache cache);
-
-const char* pakfire_packagecache_get_path(PakfirePackageCache cache);
-
-int pakfire_packagecache_has_package(PakfirePackageCache cache, PakfirePackage pkg);
-
-#ifdef PAKFIRE_PRIVATE
-
-struct _PakfirePackageCache {
-       PakfirePool pool;
-};
-
-#endif
-
-#endif /* PAKFIRE_PACKAGECACHE_H */
index 8b86f7518795e701f24a6c8aed61bda3deb1e375..863321401ba9490f909bb3de6c8e2cf4e67c7f26 100644 (file)
@@ -26,12 +26,14 @@ global:
        pakfire_count_packages;
        pakfire_create;
        pakfire_get_arch;
+       pakfire_get_cache_path;
        pakfire_get_installed_repo;
        pakfire_get_installonly;
        pakfire_get_path;
        pakfire_get_pool;
        pakfire_ref;
        pakfire_search;
+       pakfire_set_cache_path;
        pakfire_set_installed_repo;
        pakfire_set_installonly;
        pakfire_unref;
@@ -133,7 +135,6 @@ global:
        pakfire_package_get_buildhost;
        pakfire_package_get_buildtime;
        pakfire_package_get_cache_path;
-       pakfire_package_get_cache_full_path;
        pakfire_package_get_checksum;
        pakfire_package_get_conflicts;
        pakfire_package_get_description;
index 3634188628c20ecf38001fbacfb20f496ed157dc..1b3e9e416455cc74a0fc79531fa89790635a901f 100644 (file)
@@ -864,49 +864,28 @@ PAKFIRE_EXPORT char* pakfire_package_dump(PakfirePackage pkg, int flags) {
 }
 
 PAKFIRE_EXPORT int pakfire_package_is_cached(PakfirePackage pkg) {
-       PakfirePool pool = pakfire_get_pool(pkg->pakfire);
-       PakfireCache cache = pakfire_pool_get_cache(pool);
-       pakfire_pool_unref(pool);
+       char* path = pakfire_package_get_cache_path(pkg);
 
-       if (!cache)
-               return 1;
+       // Check if the file is readable
+       int r = access(path, R_OK);
+       pakfire_free(path);
 
-       return pakfire_cache_has_package(cache, pkg);
+       return r;
 }
 
 PAKFIRE_EXPORT char* pakfire_package_get_cache_path(PakfirePackage pkg) {
-       PakfirePool pool = pakfire_get_pool(pkg->pakfire);
-       PakfireCache cache = pakfire_pool_get_cache(pool);
-       pakfire_pool_unref(pool);
-
-       if (!cache)
-               return NULL;
+       char buffer[STRING_SIZE] = "";
 
-       return pakfire_cache_get_package_path(cache, pkg);
-}
+       const char* filename = pakfire_package_get_filename(pkg);
+       const char* checksum = pakfire_package_get_checksum(pkg);
 
-PAKFIRE_EXPORT char* pakfire_package_get_cache_full_path(PakfirePackage pkg) {
-       char* cache_path = NULL;
-
-       char* pkg_cache_path = pakfire_package_get_cache_path(pkg);
-       if (!pkg_cache_path)
+       if (strlen(checksum) < 3)
                return NULL;
 
-       PakfireRepo repo = pakfire_package_get_repo(pkg);
-       if (!repo)
-               goto out;
-
-       PakfireRepoCache repo_cache = pakfire_repo_get_cache(repo);
-       if (!repo_cache) {
-               goto out;
-       }
-
-       cache_path = pakfire_repocache_get_full_path(repo_cache, pkg_cache_path);
-
-out:
-       pakfire_repo_unref(repo);
+       snprintf(buffer, sizeof(buffer), "%c%c/%s/%s", checksum[0], checksum[1],
+               checksum + 2, filename);
 
-       return cache_path;
+       return pakfire_get_cache_path(pkg->pakfire, buffer);
 }
 
 PAKFIRE_EXPORT PakfireArchive pakfire_package_get_archive(PakfirePackage pkg) {
@@ -915,7 +894,7 @@ PAKFIRE_EXPORT PakfireArchive pakfire_package_get_archive(PakfirePackage pkg) {
                return pakfire_archive_ref(pkg->archive);
 
        // Otherwise open the archive from the cache
-       char* path = pakfire_package_get_cache_full_path(pkg);
+       char* path = pakfire_package_get_cache_path(pkg);
        PakfireArchive archive = pakfire_archive_open(pkg->pakfire, path);
 
        // Free resources
diff --git a/src/libpakfire/packagecache.c b/src/libpakfire/packagecache.c
deleted file mode 100644 (file)
index 5391147..0000000
+++ /dev/null
@@ -1,72 +0,0 @@
-/*#############################################################################
-#                                                                             #
-# Pakfire - The IPFire package management system                              #
-# Copyright (C) 2013 Pakfire development team                                 #
-#                                                                             #
-# This program is free software: you can redistribute it and/or modify        #
-# it under the terms of the GNU General Public License as published by        #
-# the Free Software Foundation, either version 3 of the License, or           #
-# (at your option) any later version.                                         #
-#                                                                             #
-# This program is distributed in the hope that it will be useful,             #
-# but WITHOUT ANY WARRANTY; without even the implied warranty of              #
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #
-# GNU General Public License for more details.                                #
-#                                                                             #
-# You should have received a copy of the GNU General Public License           #
-# along with this program.  If not, see <http://www.gnu.org/licenses/>.       #
-#                                                                             #
-#############################################################################*/
-
-#include <sys/stat.h>
-
-#include <pakfire/constants.h>
-#include <pakfire/package.h>
-#include <pakfire/packagecache.h>
-#include <pakfire/private.h>
-#include <pakfire/types.h>
-#include <pakfire/util.h>
-
-PAKFIRE_EXPORT PakfirePackageCache pakfire_packagecache_create(PakfirePool pool, const char* path) {
-       PakfirePackageCache cache = pakfire_calloc(1, sizeof(*cache));
-
-       cache->pool = pool;
-       cache->path = pakfire_strdup(path);
-
-       return cache;
-}
-
-PAKFIRE_EXPORT void pakfire_packagecache_free(PakfirePackageCache cache) {
-       pakfire_free(cache->path);
-       pakfire_free(cache);
-}
-
-PAKFIRE_EXPORT const char* pakfire_packagecache_get_path(PakfirePackageCache cache) {
-       return cache->path;
-}
-
-PAKFIRE_EXPORT char* pakfire_packagecache_get_package_path(PakfirePackageCache cache, PakfirePackage pkg) {
-       char buffer[STRING_SIZE] = "";
-
-       const char* filename = pakfire_package_get_filename(pkg);
-       const char* checksum = pakfire_package_get_checksum(pkg);
-
-       if (strlen(checksum) < 3)
-               return NULL;
-
-       snprintf(buffer, sizeof(buffer), "%s/%c%c/%s/%s", cache->path,
-               checksum[0], checksum[1], checksum + 2, filename);
-
-       return pakfire_strdup(buffer);
-}
-
-PAKFIRE_EXPORT int pakfire_packagecache_has_package(PakfirePackageCache cache, PakfirePackage pkg) {
-       char* filename = pakfire_packagecache_get_package_path(cache, pkg);
-
-       // Check if stat() is successful.
-       struct stat buf;
-       int r = stat(filename, &buf);
-
-       pakfire_free(filename);
-       return (r == 0);
-}
index f30725a6f46af002779dc41a68bf707963700301..f86e597e7dab9c6701d58ba1f3102d863201a102 100644 (file)
@@ -200,30 +200,18 @@ PAKFIRE_EXPORT ssize_t pakfire_step_get_installsizechange(PakfireStep step) {
 }
 
 PAKFIRE_EXPORT int pakfire_step_needs_download(PakfireStep step) {
-       PakfirePool pool = NULL;
-       int ret = true;
-
        if (!pakfire_step_get_downloadtype(step))
                return false;
 
        PakfireRepo repo = pakfire_package_get_repo(step->package);
-       if (pakfire_repo_is_installed_repo(repo)) {
-               ret = false;
-               goto finish;
-       }
-
-       pool = pakfire_get_pool(step->pakfire);
-       PakfireCache cache = pakfire_pool_get_cache(pool);
-       if (!cache)
-               goto finish;
+       if (pakfire_repo_is_installed_repo(repo))
+               return false;
 
        // Return false if package is in cache.
-       ret = !pakfire_cache_has_package(cache, step->package);
-
-finish:
-       pakfire_pool_unref(pool);
+       if (pakfire_package_is_cached(step->package) == 0)
+               return false;
 
-       return ret;
+       return true;
 }
 
 static int pakfire_step_verify(PakfireStep step) {