refactor: remove dead API, rename to_disk/config_is_remote_dest, fix perror newlines

- Delete unused public array_list_extend (made static)
- Delete legacy 16-parameter parallel_scanner_create wrapper; migrate test to parallel_scanner_create_with_options
- Rename to_disk -> file_write_to_disk and is_remote_dest -> config_is_remote_dest for module_action naming convention
- Remove stray newlines in perror calls (perror already appends one)
This commit is contained in:
2026-08-30 13:50:42 +02:00
parent 1abc17142f
commit f2917eb163
19 changed files with 59 additions and 81 deletions
+2 -2
View File
@@ -739,7 +739,7 @@ int send_files_multithreaded(Config* config) {
sender_created = (thrd_create(&sender, send_chunks_multithreaded, context) == thrd_success); sender_created = (thrd_create(&sender, send_chunks_multithreaded, context) == thrd_success);
if (!scanner_created || !loader_created || !sender_created) { if (!scanner_created || !loader_created || !sender_created) {
perror("Error creating threads.\n"); perror("Error creating threads");
pipeline_cancel(context); pipeline_cancel(context);
mtx_lock(&context->mutex_progress); mtx_lock(&context->mutex_progress);
context->sender_done = true; context->sender_done = true;
@@ -759,7 +759,7 @@ int send_files_multithreaded(Config* config) {
if (config->show_progress) { if (config->show_progress) {
progress_created = (thrd_create(&progress, progress_thread_fn, context) == thrd_success); progress_created = (thrd_create(&progress, progress_thread_fn, context) == thrd_success);
if (!progress_created) { if (!progress_created) {
perror("Error creating progress thread.\n"); perror("Error creating progress thread");
/* Non-fatal; continue without progress reporting */ /* Non-fatal; continue without progress reporting */
} }
} }
-14
View File
@@ -645,20 +645,6 @@ ParallelScanner* parallel_scanner_create_with_options(const char* root_directory
return ps; return ps;
} }
ParallelScanner* parallel_scanner_create(const char* root_directory, bool use_metadata,
unsigned long long chunk_size, char** exclude_patterns,
int exclude_count, char** include_patterns,
int include_count, unsigned long long max_size,
unsigned long long min_size, int max_depth,
int num_threads, bool follow_symlinks, bool copy_links,
bool safe_links, bool copy_unsafe_links, bool checksum) {
ScannerOptions options = {use_metadata, chunk_size, exclude_patterns, exclude_count,
include_patterns, include_count, max_size, min_size,
max_depth, num_threads, follow_symlinks, copy_links,
safe_links, copy_unsafe_links, checksum};
return parallel_scanner_create_with_options(root_directory, &options);
}
Chunk* parallel_scanner_next(ParallelScanner* ps) { Chunk* parallel_scanner_next(ParallelScanner* ps) {
if (ps->initial_chunk) { if (ps->initial_chunk) {
Chunk* c = ps->initial_chunk; Chunk* c = ps->initial_chunk;
-7
View File
@@ -77,13 +77,6 @@ Chunk* directory_scanner_next(DirectoryScanner* scanner);
bool directory_scanner_failed(const DirectoryScanner* scanner); bool directory_scanner_failed(const DirectoryScanner* scanner);
void directory_scanner_destroy(DirectoryScanner* scanner); void directory_scanner_destroy(DirectoryScanner* scanner);
ParallelScanner* parallel_scanner_create(const char* root_directory, bool use_metadata,
unsigned long long chunk_size, char** exclude_patterns,
int exclude_count, char** include_patterns,
int include_count, unsigned long long max_size,
unsigned long long min_size, int max_depth,
int num_threads, bool follow_symlinks, bool copy_links,
bool safe_links, bool copy_unsafe_links, bool checksum);
ParallelScanner* parallel_scanner_create_with_options(const char* root_directory, ParallelScanner* parallel_scanner_create_with_options(const char* root_directory,
const ScannerOptions* options); const ScannerOptions* options);
Chunk* parallel_scanner_next(ParallelScanner* scanner); Chunk* parallel_scanner_next(ParallelScanner* scanner);
+1 -1
View File
@@ -34,7 +34,7 @@ void array_list_delete(ArrayList* array_list) {
free(array_list); free(array_list);
} }
bool array_list_extend(ArrayList* array_list) { static bool array_list_extend(ArrayList* array_list) {
if (array_list == NULL) if (array_list == NULL)
return false; return false;
int new_capacity = array_list->capacity * 2; int new_capacity = array_list->capacity * 2;
-1
View File
@@ -14,7 +14,6 @@ typedef struct ArrayList {
ArrayList* array_list_create(void (*item_destroyer)(void* item)); ArrayList* array_list_create(void (*item_destroyer)(void* item));
void array_list_delete(ArrayList* array_list); void array_list_delete(ArrayList* array_list);
bool array_list_extend(ArrayList* array_list);
bool array_list_add(ArrayList* array_list, void* item); bool array_list_add(ArrayList* array_list, void* item);
void** array_list_to_array(const ArrayList* array_list); void** array_list_to_array(const ArrayList* array_list);
+2 -2
View File
@@ -108,7 +108,7 @@ Config* config_create(void) {
return config; return config;
} }
bool is_remote_dest(const char* s) { bool config_is_remote_dest(const char* s) {
if (s == NULL) if (s == NULL)
return false; return false;
const char* colon = strchr(s, ':'); const char* colon = strchr(s, ':');
@@ -124,7 +124,7 @@ bool is_remote_dest(const char* s) {
} }
void config_parse_ssh_dest(Config* config) { void config_parse_ssh_dest(Config* config) {
if (!is_remote_dest(config->receive_root_directory)) if (!config_is_remote_dest(config->receive_root_directory))
return; return;
config->transport = TRANSPORT_SSH; config->transport = TRANSPORT_SSH;
config->ssh_destination = str_dup(config->receive_root_directory); config->ssh_destination = str_dup(config->receive_root_directory);
+1 -1
View File
@@ -135,7 +135,7 @@ Config* config_create(void);
void config_delete(Config* config); void config_delete(Config* config);
bool config_send(int file_descriptor, const Config* config); bool config_send(int file_descriptor, const Config* config);
Config* config_receive(int file_descriptor); Config* config_receive(int file_descriptor);
bool is_remote_dest(const char* s); bool config_is_remote_dest(const char* s);
void config_parse_ssh_dest(Config* config); void config_parse_ssh_dest(Config* config);
#endif #endif
+1 -1
View File
@@ -647,7 +647,7 @@ File* receive_incremental_check(int fd, const Config* config, bool* skipped) {
return file; return file;
} }
bool to_disk(const char* path, const void* data, unsigned long long data_size, bool inplace, bool file_write_to_disk(const char* path, const void* data, unsigned long long data_size, bool inplace,
bool sparse) { bool sparse) {
if (!path || (!data && data_size != 0) || has_path_traversal(path)) if (!path || (!data && data_size != 0) || has_path_traversal(path))
return false; return false;
+1 -1
View File
@@ -35,7 +35,7 @@ bool file_send_sendfile(File* file, int file_descriptor, bool use_metadata, int
size_t file_content_to_buffer(File* file); size_t file_content_to_buffer(File* file);
FileMetadata* file_metadata_create(const struct stat* stats); FileMetadata* file_metadata_create(const struct stat* stats);
void file_metadata_destroy(void* metadata); void file_metadata_destroy(void* metadata);
bool to_disk(const char* path, const void* data, unsigned long long data_size, bool inplace, bool file_write_to_disk(const char* path, const void* data, unsigned long long data_size, bool inplace,
bool sparse); bool sparse);
bool file_save_to_disk(const char* root_directory, const File* file, const Config* config); bool file_save_to_disk(const char* root_directory, const File* file, const Config* config);
bool file_set_authorized_root(int fd, const char* canonical_path); bool file_set_authorized_root(int fd, const char* canonical_path);
+3 -3
View File
@@ -11,7 +11,7 @@ static void test_file_operations() {
char* test_content = "Hello, Chunk System!"; char* test_content = "Hello, Chunk System!";
unsigned long long test_len = strlen(test_content); unsigned long long test_len = strlen(test_content);
to_disk(test_path, test_content, test_len, false, false); file_write_to_disk(test_path, test_content, test_len, false, false);
File* f = file_create(test_path); File* f = file_create(test_path);
EXPECT_NOT_NULL(f); EXPECT_NOT_NULL(f);
@@ -43,8 +43,8 @@ static void test_chunk_operations() {
char* content2 = "chunk item number 2"; char* content2 = "chunk item number 2";
unsigned long long len2 = strlen(content2); unsigned long long len2 = strlen(content2);
to_disk(path1, content1, len1, false, false); file_write_to_disk(path1, content1, len1, false, false);
to_disk(path2, content2, len2, false, false); file_write_to_disk(path2, content2, len2, false, false);
struct stat st1, st2; struct stat st1, st2;
stat(path1, &st1); stat(path1, &st1);
+2 -2
View File
@@ -62,8 +62,8 @@ static void test_chunk_compress_decompress_roundtrip() {
char* content2 = "chunk compression test file 2 with more data"; char* content2 = "chunk compression test file 2 with more data";
unsigned long long len2 = strlen(content2); unsigned long long len2 = strlen(content2);
to_disk(path1, content1, len1, false, false); file_write_to_disk(path1, content1, len1, false, false);
to_disk(path2, content2, len2, false, false); file_write_to_disk(path2, content2, len2, false, false);
struct stat st1, st2; struct stat st1, st2;
EXPECT_EQ_INT(stat(path1, &st1), 0); EXPECT_EQ_INT(stat(path1, &st1), 0);
+15 -15
View File
@@ -244,26 +244,26 @@ static void test_config_receive_truncated() {
close(p[1]); close(p[1]);
} }
static void test_is_remote_dest() { static void test_config_is_remote_dest() {
/* Valid SSH-style destinations */ /* Valid SSH-style destinations */
EXPECT_TRUE(is_remote_dest("user@host:/path")); EXPECT_TRUE(config_is_remote_dest("user@host:/path"));
EXPECT_TRUE(is_remote_dest("host:/path")); EXPECT_TRUE(config_is_remote_dest("host:/path"));
EXPECT_TRUE(is_remote_dest("user@192.168.1.1:/remote/path")); EXPECT_TRUE(config_is_remote_dest("user@192.168.1.1:/remote/path"));
/* Invalid destinations */ /* Invalid destinations */
EXPECT_FALSE(is_remote_dest(NULL)); EXPECT_FALSE(config_is_remote_dest(NULL));
EXPECT_FALSE(is_remote_dest("")); EXPECT_FALSE(config_is_remote_dest(""));
EXPECT_FALSE(is_remote_dest(":")); EXPECT_FALSE(config_is_remote_dest(":"));
EXPECT_FALSE(is_remote_dest("/local/path")); EXPECT_FALSE(config_is_remote_dest("/local/path"));
EXPECT_FALSE(is_remote_dest("relative/path")); EXPECT_FALSE(config_is_remote_dest("relative/path"));
/* C:/windows/path is treated as remote (colon with no preceding slash) */ /* C:/windows/path is treated as remote (colon with no preceding slash) */
EXPECT_TRUE(is_remote_dest("C:/windows/path")); EXPECT_TRUE(config_is_remote_dest("C:/windows/path"));
/* Edge cases */ /* Edge cases */
EXPECT_FALSE(is_remote_dest("noslash")); EXPECT_FALSE(config_is_remote_dest("noslash"));
EXPECT_FALSE(is_remote_dest("/")); EXPECT_FALSE(config_is_remote_dest("/"));
EXPECT_TRUE(is_remote_dest("host:")); EXPECT_TRUE(config_is_remote_dest("host:"));
EXPECT_TRUE(is_remote_dest("user@host:")); EXPECT_TRUE(config_is_remote_dest("user@host:"));
} }
void test_config() { void test_config() {
@@ -278,5 +278,5 @@ void test_config() {
test_config_send_receive_version_mismatch(); test_config_send_receive_version_mismatch();
test_config_receive_truncated(); test_config_receive_truncated();
} }
test_is_remote_dest(); test_config_is_remote_dest();
} }
+20 -20
View File
@@ -34,7 +34,7 @@ static void test_file_destroy_normal() {
static void test_file_load_data() { static void test_file_load_data() {
const char* content = "Hello Load Test"; const char* content = "Hello Load Test";
EXPECT_TRUE(to_disk("test_file_load_data.txt", content, strlen(content), false, false)); EXPECT_TRUE(file_write_to_disk("test_file_load_data.txt", content, strlen(content), false, false));
struct stat st; struct stat st;
EXPECT_EQ_INT(stat("test_file_load_data.txt", &st), 0); EXPECT_EQ_INT(stat("test_file_load_data.txt", &st), 0);
@@ -87,15 +87,15 @@ static void test_file_save_to_disk() {
rmdir("test_save_tmp"); rmdir("test_save_tmp");
} }
static void test_to_disk_basic() { static void test_file_write_to_disk_basic() {
const char* content = "Basic to_disk test"; const char* content = "Basic file_write_to_disk test";
EXPECT_TRUE(to_disk("test_to_disk_basic.txt", content, strlen(content), false, false)); EXPECT_TRUE(file_write_to_disk("test_file_write_to_disk_basic.txt", content, strlen(content), false, false));
struct stat st; struct stat st;
EXPECT_EQ_INT(stat("test_to_disk_basic.txt", &st), 0); EXPECT_EQ_INT(stat("test_file_write_to_disk_basic.txt", &st), 0);
EXPECT_EQ_INT((int)st.st_size, (int)strlen(content)); EXPECT_EQ_INT((int)st.st_size, (int)strlen(content));
FILE* fp = fopen("test_to_disk_basic.txt", "rb"); FILE* fp = fopen("test_file_write_to_disk_basic.txt", "rb");
EXPECT_NOT_NULL(fp); EXPECT_NOT_NULL(fp);
char buf[100]; char buf[100];
size_t nread = fread(buf, 1, sizeof(buf), fp); size_t nread = fread(buf, 1, sizeof(buf), fp);
@@ -103,12 +103,12 @@ static void test_to_disk_basic() {
EXPECT_EQ_INT((int)nread, (int)strlen(content)); EXPECT_EQ_INT((int)nread, (int)strlen(content));
EXPECT_EQ_INT(memcmp(buf, content, strlen(content)), 0); EXPECT_EQ_INT(memcmp(buf, content, strlen(content)), 0);
unlink("test_to_disk_basic.txt"); unlink("test_file_write_to_disk_basic.txt");
} }
static void test_to_disk_creates_dirs() { static void test_file_write_to_disk_creates_dirs() {
const char* content = "Nested dir test"; const char* content = "Nested dir test";
EXPECT_TRUE(to_disk("test_nested_tmp/nested/file.txt", content, strlen(content), false, false)); EXPECT_TRUE(file_write_to_disk("test_nested_tmp/nested/file.txt", content, strlen(content), false, false));
struct stat st; struct stat st;
EXPECT_EQ_INT(stat("test_nested_tmp/nested/file.txt", &st), 0); EXPECT_EQ_INT(stat("test_nested_tmp/nested/file.txt", &st), 0);
@@ -126,15 +126,15 @@ static void test_to_disk_creates_dirs() {
rmdir("test_nested_tmp"); rmdir("test_nested_tmp");
} }
static void test_to_disk_does_not_follow_symlink() { static void test_file_write_to_disk_does_not_follow_symlink() {
const char* outside = "test_to_disk_outside.txt"; const char* outside = "test_file_write_to_disk_outside.txt";
const char* link = "test_to_disk_link.txt"; const char* link = "test_file_write_to_disk_link.txt";
const char* content = "confined"; const char* content = "confined";
unlink(outside); unlink(outside);
unlink(link); unlink(link);
EXPECT_TRUE(to_disk(outside, "outside", 7, false, false)); EXPECT_TRUE(file_write_to_disk(outside, "outside", 7, false, false));
EXPECT_EQ_INT(symlink(outside, link), 0); EXPECT_EQ_INT(symlink(outside, link), 0);
EXPECT_TRUE(to_disk(link, content, strlen(content), false, false)); EXPECT_TRUE(file_write_to_disk(link, content, strlen(content), false, false));
FILE* fp = fopen(outside, "rb"); FILE* fp = fopen(outside, "rb");
char buf[16] = {0}; char buf[16] = {0};
EXPECT_NOT_NULL(fp); EXPECT_NOT_NULL(fp);
@@ -151,7 +151,7 @@ static void test_to_disk_does_not_follow_symlink() {
static void test_file_content_to_buffer() { static void test_file_content_to_buffer() {
const char* content = "Buffer content test"; const char* content = "Buffer content test";
EXPECT_TRUE(to_disk("test_buffer_file.txt", content, strlen(content), false, false)); EXPECT_TRUE(file_write_to_disk("test_buffer_file.txt", content, strlen(content), false, false));
File* f = file_create("test_buffer_file.txt"); File* f = file_create("test_buffer_file.txt");
EXPECT_NOT_NULL(f); EXPECT_NOT_NULL(f);
@@ -273,7 +273,7 @@ static void test_file_send_no_path() {
} }
static void test_file_metadata_create() { static void test_file_metadata_create() {
EXPECT_TRUE(to_disk("test_meta_file.txt", "metadata test", 13, false, false)); EXPECT_TRUE(file_write_to_disk("test_meta_file.txt", "metadata test", 13, false, false));
struct stat st; struct stat st;
EXPECT_EQ_INT(stat("test_meta_file.txt", &st), 0); EXPECT_EQ_INT(stat("test_meta_file.txt", &st), 0);
@@ -382,7 +382,7 @@ static void test_file_send_single_calls_metadata_and_path() {
/* Create a real file on disk so we can have metadata */ /* Create a real file on disk so we can have metadata */
const char* content = "File with metadata"; const char* content = "File with metadata";
size_t len = strlen(content); size_t len = strlen(content);
EXPECT_TRUE(to_disk("test_meta_send.txt", content, len, false, false)); EXPECT_TRUE(file_write_to_disk("test_meta_send.txt", content, len, false, false));
struct stat st; struct stat st;
EXPECT_EQ_INT(stat("test_meta_send.txt", &st), 0); EXPECT_EQ_INT(stat("test_meta_send.txt", &st), 0);
@@ -455,9 +455,9 @@ void test_file() {
test_file_load_data(); test_file_load_data();
test_file_load_data_missing_file(); test_file_load_data_missing_file();
test_file_save_to_disk(); test_file_save_to_disk();
test_to_disk_basic(); test_file_write_to_disk_basic();
test_to_disk_creates_dirs(); test_file_write_to_disk_creates_dirs();
test_to_disk_does_not_follow_symlink(); test_file_write_to_disk_does_not_follow_symlink();
test_file_content_to_buffer(); test_file_content_to_buffer();
test_file_save_to_disk_path_traversal(); test_file_save_to_disk_path_traversal();
test_file_save_to_disk_deep_traversal(); test_file_save_to_disk_deep_traversal();
+4 -4
View File
@@ -15,7 +15,7 @@
static void test_sendfile_basic() { static void test_sendfile_basic() {
const char* content = "Hello from sendfile test!"; const char* content = "Hello from sendfile test!";
size_t len = strlen(content); size_t len = strlen(content);
EXPECT_TRUE(to_disk("test_sendfile_basic.txt", content, len, false, false)); EXPECT_TRUE(file_write_to_disk("test_sendfile_basic.txt", content, len, false, false));
File* file = file_create("test_sendfile_basic.txt"); File* file = file_create("test_sendfile_basic.txt");
EXPECT_NOT_NULL(file); EXPECT_NOT_NULL(file);
@@ -77,7 +77,7 @@ static void test_sendfile_basic() {
static void test_sendfile_empty_file() { static void test_sendfile_empty_file() {
const char* content = ""; const char* content = "";
size_t len = 0; size_t len = 0;
EXPECT_TRUE(to_disk("test_sendfile_empty.txt", content, len, false, false)); EXPECT_TRUE(file_write_to_disk("test_sendfile_empty.txt", content, len, false, false));
File* file = file_create("test_sendfile_empty.txt"); File* file = file_create("test_sendfile_empty.txt");
EXPECT_NOT_NULL(file); EXPECT_NOT_NULL(file);
@@ -156,7 +156,7 @@ static void test_sendfile_missing_file() {
static void test_sendfile_compression_fallback() { static void test_sendfile_compression_fallback() {
const char* content = "Compression fallback content"; const char* content = "Compression fallback content";
size_t len = strlen(content); size_t len = strlen(content);
EXPECT_TRUE(to_disk("test_sendfile_comp.txt", content, len, false, false)); EXPECT_TRUE(file_write_to_disk("test_sendfile_comp.txt", content, len, false, false));
struct stat st; struct stat st;
EXPECT_EQ_INT(stat("test_sendfile_comp.txt", &st), 0); EXPECT_EQ_INT(stat("test_sendfile_comp.txt", &st), 0);
@@ -222,7 +222,7 @@ static void test_sendfile_compression_fallback() {
static void test_sendfile_no_path() { static void test_sendfile_no_path() {
const char* content = "No path sendfile test"; const char* content = "No path sendfile test";
size_t len = strlen(content); size_t len = strlen(content);
EXPECT_TRUE(to_disk("test_sendfile_nopath.txt", content, len, false, false)); EXPECT_TRUE(file_write_to_disk("test_sendfile_nopath.txt", content, len, false, false));
File* file = file_create("test_sendfile_nopath.txt"); File* file = file_create("test_sendfile_nopath.txt");
EXPECT_NOT_NULL(file); EXPECT_NOT_NULL(file);
+1 -1
View File
@@ -101,7 +101,7 @@ static void test_fuzz_delta_deserialize() {
/* Smoke test for metadata_from_buf fuzz target */ /* Smoke test for metadata_from_buf fuzz target */
static void test_fuzz_metadata_from_buf() { static void test_fuzz_metadata_from_buf() {
/* Create a real file to get metadata from */ /* Create a real file to get metadata from */
EXPECT_TRUE(to_disk("fuzz_meta_test.txt", "metadata test", 13, false, false)); EXPECT_TRUE(file_write_to_disk("fuzz_meta_test.txt", "metadata test", 13, false, false));
struct stat st; struct stat st;
EXPECT_EQ_INT(stat("fuzz_meta_test.txt", &st), 0); EXPECT_EQ_INT(stat("fuzz_meta_test.txt", &st), 0);
+1 -1
View File
@@ -125,7 +125,7 @@ static void test_metadata_rejects_invalid_values() {
static void test_file_restore_metadata() { static void test_file_restore_metadata() {
const char* path = "temp_meta_restore_test.txt"; const char* path = "temp_meta_restore_test.txt";
const char* content = "test content"; const char* content = "test content";
EXPECT_TRUE(to_disk(path, content, strlen(content), false, false)); EXPECT_TRUE(file_write_to_disk(path, content, strlen(content), false, false));
FileMetadata m; FileMetadata m;
m.mode = 0644; m.mode = 0644;
+1 -1
View File
@@ -84,7 +84,7 @@ static void test_property_chunk_roundtrip() {
for (int i = 0; i < content_len; i++) for (int i = 0; i < content_len; i++)
content[i] = (char)(rand() % 256); content[i] = (char)(rand() % 256);
to_disk(path, content, content_len, false, false); file_write_to_disk(path, content, content_len, false, false);
struct stat st; struct stat st;
stat(path, &st); stat(path, &st);
+1 -1
View File
@@ -13,7 +13,7 @@
static void test_chunk_deserialize_truncated() { static void test_chunk_deserialize_truncated() {
char* path = "test_rob_trunc.txt"; char* path = "test_rob_trunc.txt";
char* content = "hello"; char* content = "hello";
to_disk(path, content, strlen(content), false, false); file_write_to_disk(path, content, strlen(content), false, false);
struct stat st; struct stat st;
stat(path, &st); stat(path, &st);
+3 -3
View File
@@ -7,7 +7,7 @@
#include <unistd.h> #include <unistd.h>
static void create_test_file(const char* path, const char* content) { static void create_test_file(const char* path, const char* content) {
(void)to_disk(path, content, strlen(content), false, false); (void)file_write_to_disk(path, content, strlen(content), false, false);
} }
static void test_scanner_single_file() { static void test_scanner_single_file() {
@@ -394,8 +394,8 @@ static void test_parallel_scanner_root_chunks_without_workers() {
create_test_file(file1, "a"); create_test_file(file1, "a");
create_test_file(file2, "b"); create_test_file(file2, "b");
ParallelScanner* scanner = parallel_scanner_create(dir, false, 1, NULL, 0, NULL, 0, 0, 0, 0, 0, ScannerOptions options = {false, 1, NULL, 0, NULL, 0, 0, 0, 0, 0, false, false, false, false, false};
false, false, false, false, false); ParallelScanner* scanner = parallel_scanner_create_with_options(dir, &options);
EXPECT_NOT_NULL(scanner); EXPECT_NOT_NULL(scanner);
int total_files = 0; int total_files = 0;