1 /*#############################################################################
3 # Pakfire - The IPFire package management system #
4 # Copyright (C) 2013 Pakfire development team #
6 # This program is free software: you can redistribute it and/or modify #
7 # it under the terms of the GNU General Public License as published by #
8 # the Free Software Foundation, either version 3 of the License, or #
9 # (at your option) any later version. #
11 # This program is distributed in the hope that it will be useful, #
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
14 # GNU General Public License for more details. #
16 # You should have received a copy of the GNU General Public License #
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
19 #############################################################################*/
21 #define _XOPEN_SOURCE 500
26 #include <pakfire/cache.h>
27 #include <pakfire/constants.h>
28 #include <pakfire/package.h>
29 #include <pakfire/private.h>
30 #include <pakfire/repo.h>
31 #include <pakfire/repocache.h>
32 #include <pakfire/types.h>
33 #include <pakfire/util.h>
35 static char* pakfire_repocache_prefix(PakfireRepoCache repo_cache
) {
36 const char* repo_name
= pakfire_repo_get_name(repo_cache
->repo
);
38 char buffer
[STRING_SIZE
] = "";
39 snprintf(buffer
, sizeof(buffer
), "repodata/%s", repo_name
);
41 return pakfire_strdup(buffer
);
44 PAKFIRE_EXPORT PakfireRepoCache
pakfire_repocache_create(PakfireRepo repo
) {
45 PakfireRepoCache repo_cache
= pakfire_calloc(1, sizeof(*repo_cache
));
47 repo_cache
->repo
= repo
;
48 repo_cache
->prefix
= pakfire_repocache_prefix(repo_cache
);
53 PAKFIRE_EXPORT
void pakfire_repocache_free(PakfireRepoCache repo_cache
) {
54 pakfire_free(repo_cache
->prefix
);
55 pakfire_free(repo_cache
);
58 PAKFIRE_EXPORT
char* pakfire_repocache_get_cache_path(PakfireRepoCache repo_cache
, const char* path
) {
59 return pakfire_path_join(repo_cache
->prefix
, path
);
62 PAKFIRE_EXPORT
char* pakfire_repocache_get_full_path(PakfireRepoCache repo_cache
, const char* path
) {
63 char* cache_path
= pakfire_repocache_get_cache_path(repo_cache
, path
);
65 PakfireCache cache
= pakfire_repocache_cache(repo_cache
);
66 char* full_path
= pakfire_cache_get_full_path(cache
, cache_path
);
68 pakfire_free(cache_path
);
73 PAKFIRE_EXPORT
int pakfire_repocache_has_file(PakfireRepoCache repo_cache
, const char* filename
) {
74 char* cache_filename
= pakfire_repocache_get_cache_path(repo_cache
, filename
);
76 PakfireCache cache
= pakfire_repocache_cache(repo_cache
);
77 int r
= pakfire_cache_has_file(cache
, cache_filename
);
79 pakfire_free(cache_filename
);
83 PAKFIRE_EXPORT
int pakfire_repocache_age(PakfireRepoCache repo_cache
, const char* filename
) {
84 char* cache_filename
= pakfire_repocache_get_cache_path(repo_cache
, filename
);
86 PakfireCache cache
= pakfire_repocache_cache(repo_cache
);
87 int age
= pakfire_cache_age(cache
, cache_filename
);
88 pakfire_free(cache_filename
);
93 PAKFIRE_EXPORT
FILE* pakfire_repocache_open(PakfireRepoCache repo_cache
, const char* filename
, const char* flags
) {
94 char* cache_filename
= pakfire_repocache_get_cache_path(repo_cache
, filename
);
96 PakfireCache cache
= pakfire_repocache_cache(repo_cache
);
97 FILE* fp
= pakfire_cache_open(cache
, cache_filename
, flags
);
98 pakfire_free(cache_filename
);