]> git.ipfire.org Git - thirdparty/FORT-validator.git/commitdiff
Download HTTPS update to tmp/ before https/
authorAlberto Leiva Popper <ydahhrk@gmail.com>
Fri, 31 Oct 2025 22:31:29 +0000 (16:31 -0600)
committerAlberto Leiva Popper <ydahhrk@gmail.com>
Fri, 31 Oct 2025 22:31:29 +0000 (16:31 -0600)
Prevents certain failed downloads from overriding a possibly good file
with trash.

src/cache.c
src/file.c
src/file.h

index 4c615a9829eba71b821b15451d26cdbe6c220456..82b6413af21131da8e5296d48116099a02668393 100644 (file)
@@ -797,13 +797,20 @@ dl_rrdp(struct cache_node *notif)
 static validation_verdict
 dl_http(struct cache_node *file)
 {
+       char tmppath[CACHE_TMPFILE_BUFLEN];
        bool changed;
 
-       if (http_download(&file->key.http, file->path, file->success_ts,
-                         &changed))
+       cache_tmpfile(tmppath);
+
+       if (http_download(&file->key.http, tmppath, file->success_ts, &changed))
                return VV_FAIL;
-       if (changed)
+
+       if (changed) {
+               if (file_mv(tmppath, file->path) != 0)
+                       return VV_FAIL;
                file->success_ts = file->attempt_ts;
+       }
+
        return VV_CONTINUE;
 }
 
index fad2e95920815f8ad59d6cf5f81a2e6b8515111d..2f34545fafc54902183371cf14313b923387bb38 100644 (file)
@@ -272,6 +272,21 @@ file_mkdir(char const *path, bool force)
        return 0;
 }
 
+int
+file_mv(char const *from, char const *to)
+{
+       int error;
+
+       pr_trc("mv %s %s", from, to);
+       if (rename(from, to) < 0) {
+               error = errno;
+               pr_err("Cannot move %s to %s: %s", from, to, strerror(errno));
+               return error;
+       }
+
+       return 0;
+}
+
 void
 file_ln(char const *oldpath, char const *newpath)
 {
index f8058a06689ebf19485b8854a8cc80c344d81e6c..0630babf7543087fd08837735d95777a4a898cb5 100644 (file)
@@ -35,8 +35,8 @@ bool file_is_valid(char const *, bool);
 
 int file_rm_f(char const *);
 int file_rm_rf(char const *);
-
 int file_mkdir(char const *, bool);
+int file_mv(char const *, char const *);
 void file_ln(char const *, char const *);
 
 struct cache_sequence {