Merge remote-tracking branch 'origin/feat/existing' into dev

This commit is contained in:
2026-09-04 17:50:55 +02:00
parent 192aff8c46
commit c650f9a3d0
11 changed files with 123 additions and 70 deletions
+18 -1
View File
@@ -29,6 +29,7 @@ bool file_save_to_disk(const char* root_directory, const File* file, const Confi
const char* backup_dir = (config && config->backup_dir) ? config->backup_dir : NULL;
const char* partial_dir = (config && config->partial_dir) ? config->partial_dir : NULL;
char *confined_backup = NULL, *confined_partial = NULL, *disk_path = NULL;
char* destination_path = NULL;
char *backup_path = NULL, *parent_copy = NULL;
if (!file || !file->path || !file->data || (file->data->size != 0 && !file->data->data) ||
@@ -54,13 +55,27 @@ bool file_save_to_disk(const char* root_directory, const File* file, const Confi
const char* actual_root =
(partial_dir && config && config->partial) ? confined_partial : root_directory;
destination_path = path_cat(root_directory, file->path);
disk_path = path_cat(actual_root, file->path);
if (disk_path == NULL) {
if (destination_path == NULL || disk_path == NULL) {
free(confined_backup);
free(confined_partial);
free(destination_path);
free(disk_path);
return false;
}
/* --existing checks the final destination, not a temporary partial path. */
if (config && config->existing && !file_path_exists_secure(destination_path)) {
free(confined_backup);
free(confined_partial);
free(destination_path);
free(disk_path);
return true;
}
free(destination_path);
destination_path = NULL;
/* --update is receiver-side policy: never replace a newer destination.
The secure stat does not require read permission on the destination. */
if (config && config->update && file_destination_is_newer_secure(disk_path, file->metadata)) {
@@ -110,6 +125,7 @@ bool file_save_to_disk(const char* root_directory, const File* file, const Confi
free(backup_path);
free(confined_backup);
free(confined_partial);
free(destination_path);
free(disk_path);
return ok;
@@ -118,6 +134,7 @@ fail:
free(backup_path);
free(confined_backup);
free(confined_partial);
free(destination_path);
free(disk_path);
return false;
}