#include <pakfire/types.h>
#include <pakfire/util.h>
+// Refresh mirrorlists once a day
+#define REFRESH_AGE_MIRRORLIST 24 * 3600
+
+// Refresh repository metadata every 10 minutes
+#define REFRESH_AGE_METADATA 600
+
const uint8_t XZ_HEADER_MAGIC[] = { 0xFD, '7', 'z', 'X', 'Z', 0x00 };
const size_t XZ_HEADER_LENGTH = sizeof(XZ_HEADER_MAGIC);
if (!mirrorlist_url || !*mirrorlist)
return 0;
+ // Check if this needs to be refreshed
+ if (!force) {
+ time_t age = pakfire_path_age(mirrorlist);
+
+ if (age > 0 && age < REFRESH_AGE_MIRRORLIST) {
+ DEBUG(repo->pakfire, "Skip refreshing mirrorlist which is %lds old\n", age);
+ return 0;
+ }
+ }
+
// Get the downloader
struct pakfire_downloader* downloader = pakfire_repo_downloader(repo);
if (!downloader)
}
static int pakfire_repo_refresh_metadata(PakfireRepo repo, const int force) {
+ // Check if this needs to be refreshed
+ if (!force) {
+ time_t age = pakfire_path_age(repo->appdata->metadata);
+
+ if (age > 0 && age < REFRESH_AGE_METADATA) {
+ DEBUG(repo->pakfire, "Skip refreshing metadata which is %lds old\n", age);
+ return 0;
+ }
+ }
+
// Get the downloader
struct pakfire_downloader* downloader = pakfire_repo_downloader(repo);
if (!downloader)
return !access(path, F_OK);
}
+time_t pakfire_path_age(const char* path) {
+ struct stat st;
+
+ int r = stat(path, &st);
+ if (r == 0) {
+ // Get current timestamp
+ time_t now = time(NULL);
+
+ // Return the difference since the file has been created and now
+ return now - st.st_ctime;
+ }
+
+ return -1;
+}
+
PAKFIRE_EXPORT int pakfire_path_isdir(const char* path) {
struct stat s;