From 6de34cfb1cfb2e07ba68bea8935ba2770621fd15 Mon Sep 17 00:00:00 2001
From: Kubat <mael.martin31@gmail.com>
Date: Thu, 17 Feb 2022 23:36:24 +0100
Subject: [PATCH] REPO-MODULE: Replace the disk mtime check with the database
 unix timestamp check

---
 src/module/module_repo.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/src/module/module_repo.c b/src/module/module_repo.c
index 58d57dfa..821e950f 100644
--- a/src/module/module_repo.c
+++ b/src/module/module_repo.c
@@ -374,6 +374,20 @@ ___handle_got_json_dl(struct kara *kara)
         return;
     }
 
+    uint64_t repo_timestamp = (uint64_t)kara->unix_timestamp;
+    if (kara->unix_timestamp < 0) {
+        LOG_ERROR("REPO",
+                  "The unix timestamp %ld from the repo is negative "
+                  "thus not valid for the kara %ld",
+                  kara->unix_timestamp, kara->id);
+        return;
+    }
+    if (!database_set_kara_repo_timestamp_id(kara->db, (int)kara->id, repo_timestamp)) {
+        LOG_ERROR("REPO", "Could not set repo timestamp to %zu for kara id %d", repo_timestamp,
+                  kara->id);
+        return;
+    }
+
     database_update_set_new(kara->db, (int)kara->id, kara->is_new);
     lkt_queue_send(kara->repo->queue, LKT_EVENT_TOUCH_KARA, (void *)(size_t)kara->id);
     database_stamp(kara->db);
@@ -453,7 +467,7 @@ ___handle_got_json_internal_callback(const char *key, const char *val, int comp,
         }
 
         /* The file changed */
-        database_get_kara_mtime_path(kara->db, kara->filename, &filestamp);
+        database_get_kara_repo_timestamp_path(kara->db, kara->filename, &filestamp);
         database_is_kara_mkv(kara->db, kara->filename, &magic_valid);
         if (filestamp == 0 || kara->unix_timestamp != (long)(uint64_t)kara->unix_timestamp ||
             filestamp <= (uint64_t)kara->unix_timestamp || (!magic_valid)) {
@@ -491,7 +505,7 @@ ___handle_got_json_internal_callback(const char *key, const char *val, int comp,
             goto do_it;
         }
 
-        database_get_kara_mtime_path(kara->db, kara->filename, &filestamp);
+        database_get_kara_repo_timestamp_path(kara->db, kara->filename, &filestamp);
         database_is_kara_mkv(kara->db, kara->filename, &magic_valid);
         if (filestamp == 0 || kara->unix_timestamp != (long)(uint64_t)kara->unix_timestamp ||
             filestamp <= (uint64_t)kara->unix_timestamp || (!magic_valid))
-- 
GitLab