From: Michael Tremer Date: Fri, 19 Jan 2018 00:43:51 +0000 (+0100) Subject: libpakfire: Move package caching into Package X-Git-Tag: 0.9.28~1285^2~1164 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3f7bcbc4916076a8d1b8631717b34182d25b4288;p=pakfire.git libpakfire: Move package caching into Package Signed-off-by: Michael Tremer --- diff --git a/Makefile.am b/Makefile.am index 01fb04c6b..b64a95a03 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 \ diff --git a/src/_pakfire/package.c b/src/_pakfire/package.c index 5d7530b4d..9468a1fba 100644 --- a/src/_pakfire/package.c +++ b/src/_pakfire/package.c @@ -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 { diff --git a/src/libpakfire/cache.c b/src/libpakfire/cache.c index 6c7a744b0..9b6f540be 100644 --- a/src/libpakfire/cache.c +++ b/src/libpakfire/cache.c @@ -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); diff --git a/src/libpakfire/include/pakfire/cache.h b/src/libpakfire/include/pakfire/cache.h index c302c5620..78d4c5902 100644 --- a/src/libpakfire/include/pakfire/cache.h +++ b/src/libpakfire/include/pakfire/cache.h @@ -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 index 9c07273ad..000000000 --- a/src/libpakfire/include/pakfire/packagecache.h +++ /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 . # -# # -#############################################################################*/ - -#ifndef PAKFIRE_PACKAGECACHE_H -#define PAKFIRE_PACKAGECACHE_H - -#include - -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 */ diff --git a/src/libpakfire/libpakfire.sym b/src/libpakfire/libpakfire.sym index 8b86f7518..863321401 100644 --- a/src/libpakfire/libpakfire.sym +++ b/src/libpakfire/libpakfire.sym @@ -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; diff --git a/src/libpakfire/package.c b/src/libpakfire/package.c index 363418862..1b3e9e416 100644 --- a/src/libpakfire/package.c +++ b/src/libpakfire/package.c @@ -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 index 5391147e4..000000000 --- a/src/libpakfire/packagecache.c +++ /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 . # -# # -#############################################################################*/ - -#include - -#include -#include -#include -#include -#include -#include - -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); -} diff --git a/src/libpakfire/step.c b/src/libpakfire/step.c index f30725a6f..f86e597e7 100644 --- a/src/libpakfire/step.c +++ b/src/libpakfire/step.c @@ -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) {