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;
}
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)
{
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 {