Merge remaining 4 PRs: memory safety, refactoring, test coverage, integration cleanup #93

Merged
TapTap merged 37 commits from merge-all into main 2026-07-21 16:08:39 +02:00
6 changed files with 50 additions and 26 deletions
Showing only changes of commit 62ff1d3929 - Show all commits
+21
View File
@@ -118,6 +118,11 @@ bool file_send_single_calls(File* file, int file_descriptor, bool use_metadata,
data_destroy(compressed_data); data_destroy(compressed_data);
return false; return false;
} }
int ft = 0; // FILE_TYPE_REGULAR
if (!send_int(file_descriptor, ft)) {
data_destroy(compressed_data);
return false;
}
if (!send_data(file_descriptor, data_to_send)) { if (!send_data(file_descriptor, data_to_send)) {
data_destroy(compressed_data); data_destroy(compressed_data);
return false; return false;
@@ -385,6 +390,13 @@ File* receive_incremental_check(int fd, const Config* config, bool* skipped) {
} }
} }
int file_type;
if (!receive_int(fd, &file_type)) {
file_destroy(file);
send_status(fd, STATUS_ERROR);
return NULL;
}
Data* file_data = receive_data(fd); Data* file_data = receive_data(fd);
if (file_data == NULL) { if (file_data == NULL) {
file_destroy(file); file_destroy(file);
@@ -462,6 +474,10 @@ bool file_send_sendfile(File* file, int file_descriptor, bool use_metadata, int
if (use_metadata && !metadata_send(file_descriptor, file->metadata)) if (use_metadata && !metadata_send(file_descriptor, file->metadata))
return false; return false;
int ft = 0; // FILE_TYPE_REGULAR
if (!send_int(file_descriptor, ft))
return false;
int fd = open(file->path, O_RDONLY); int fd = open(file->path, O_RDONLY);
if (fd == -1) { if (fd == -1) {
perror("Could not open file for sendfile"); perror("Could not open file for sendfile");
@@ -504,6 +520,11 @@ File* file_receive(const Config* config, int file_descriptor) {
return NULL; return NULL;
} }
} }
int file_type;
if (!receive_int(file_descriptor, &file_type)) {
file_destroy(file);
return NULL;
}
Data* file_data = receive_data(file_descriptor); Data* file_data = receive_data(file_descriptor);
if (file_data == NULL) { if (file_data == NULL) {
file_destroy(file); file_destroy(file);
+3
View File
@@ -217,6 +217,9 @@ static void test_file_send_no_path() {
pid_t pid = fork(); pid_t pid = fork();
if (pid == 0) { if (pid == 0) {
close(p[1]); close(p[1]);
int file_type;
EXPECT_TRUE(receive_int(p[0], &file_type));
EXPECT_EQ_INT(file_type, 0); /* FILE_TYPE_REGULAR */
Data* received = receive_data(p[0]); Data* received = receive_data(p[0]);
close(p[0]); close(p[0]);
+11 -8
View File
@@ -22,8 +22,8 @@ static void test_sendfile_basic() {
/* Set the size so file_send_sendfile can report it */ /* Set the size so file_send_sendfile can report it */
file->data->size = len; file->data->size = len;
Config* cfg = config_create(str_dup(PROTOCOL_VERSION), str_dup("/tmp"), str_dup("/tmp"), Config* cfg = config_create(str_dup(PROTOCOL_VERSION), str_dup("/tmp"), str_dup("/tmp"), false,
false, false, false, false, false, 0, false, 0); false, false, false, false, 0, false, 0);
EXPECT_NOT_NULL(cfg); EXPECT_NOT_NULL(cfg);
int p[2]; int p[2];
@@ -80,8 +80,8 @@ static void test_sendfile_empty_file() {
EXPECT_NOT_NULL(file); EXPECT_NOT_NULL(file);
file->data->size = 0; file->data->size = 0;
Config* cfg = config_create(str_dup(PROTOCOL_VERSION), str_dup("/tmp"), str_dup("/tmp"), Config* cfg = config_create(str_dup(PROTOCOL_VERSION), str_dup("/tmp"), str_dup("/tmp"), false,
false, false, false, false, false, 0, false, 0); false, false, false, false, 0, false, 0);
EXPECT_NOT_NULL(cfg); EXPECT_NOT_NULL(cfg);
int p[2]; int p[2];
@@ -161,8 +161,8 @@ static void test_sendfile_compression_fallback() {
file->data->size = (size_t)st.st_size; file->data->size = (size_t)st.st_size;
EXPECT_TRUE(file_load_data(file)); EXPECT_TRUE(file_load_data(file));
Config* cfg = config_create(str_dup(PROTOCOL_VERSION), str_dup("/tmp"), str_dup("/tmp"), Config* cfg = config_create(str_dup(PROTOCOL_VERSION), str_dup("/tmp"), str_dup("/tmp"), false,
false, false, false, true, false, 3, false, 0); false, false, true, false, 3, false, 0);
EXPECT_NOT_NULL(cfg); EXPECT_NOT_NULL(cfg);
int p[2]; int p[2];
@@ -224,8 +224,11 @@ static void test_sendfile_no_path() {
pid_t pid = fork(); pid_t pid = fork();
if (pid == 0) { if (pid == 0) {
close(p[1]); close(p[1]);
/* When send_path is false, the sender sends raw data (size + bytes) only. /* When send_path is false, the sender sends file_type + raw data (size + bytes).
* We need to receive just the Data, not a File. */ * Read file_type first with assertion, then receive data. */
int file_type;
EXPECT_TRUE(receive_int(p[0], &file_type));
EXPECT_EQ_INT(file_type, 0); /* FILE_TYPE_REGULAR */
Data* received = receive_data(p[0]); Data* received = receive_data(p[0]);
close(p[0]); close(p[0]);
+1 -1
View File
@@ -47,7 +47,7 @@ static void test_log_set_level_info() {
set_log_level(LOG_LEVEL_INFO); set_log_level(LOG_LEVEL_INFO);
/* INFO level should show INFO, WARNING, ERROR but not DEBUG */ /* INFO level should show INFO, WARNING, ERROR but not DEBUG */
log_message(LOG_LEVEL_DEBUG, "debug should be filtered"); /* filtered */ log_message(LOG_LEVEL_DEBUG, "debug should be filtered"); /* filtered */
log_message(LOG_LEVEL_INFO, "info should show"); log_message(LOG_LEVEL_INFO, "info should show");
log_message(LOG_LEVEL_WARNING, "warning should show"); log_message(LOG_LEVEL_WARNING, "warning should show");
log_message(LOG_LEVEL_ERROR, "error should show"); log_message(LOG_LEVEL_ERROR, "error should show");
+10 -10
View File
@@ -8,8 +8,8 @@
/* Test pipeline_context_sender_create/destroy with valid arguments */ /* Test pipeline_context_sender_create/destroy with valid arguments */
static void test_sender_create_destroy() { static void test_sender_create_destroy() {
Config* cfg = config_create(str_dup("1.0"), str_dup("/src"), str_dup("/dst"), Config* cfg = config_create(str_dup("1.0"), str_dup("/src"), str_dup("/dst"), false, false, false,
false, false, false, false, false, 0, false, 0); false, false, 0, false, 0);
EXPECT_NOT_NULL(cfg); EXPECT_NOT_NULL(cfg);
Queue* q_scanner = queue_create(5, NULL); Queue* q_scanner = queue_create(5, NULL);
@@ -32,8 +32,8 @@ static void test_sender_create_destroy() {
/* Test pipeline_context_receiver_create/destroy with valid arguments */ /* Test pipeline_context_receiver_create/destroy with valid arguments */
static void test_receiver_create_destroy() { static void test_receiver_create_destroy() {
Config* cfg = config_create(str_dup("2.0"), str_dup("/src"), str_dup("/dst"), Config* cfg = config_create(str_dup("2.0"), str_dup("/src"), str_dup("/dst"), true, true, false,
true, true, false, false, false, 0, false, 0); false, false, 0, false, 0);
EXPECT_NOT_NULL(cfg); EXPECT_NOT_NULL(cfg);
Queue* q = queue_create(20, NULL); Queue* q = queue_create(20, NULL);
@@ -51,8 +51,8 @@ static void test_receiver_create_destroy() {
/* Test that create handles various queue capacities */ /* Test that create handles various queue capacities */
static void test_sender_queue_capacities() { static void test_sender_queue_capacities() {
Config* cfg = config_create(str_dup("3.0"), str_dup("/src"), str_dup("/dst"), Config* cfg = config_create(str_dup("3.0"), str_dup("/src"), str_dup("/dst"), false, false, false,
false, false, false, false, false, 0, false, 0); false, false, 0, false, 0);
EXPECT_NOT_NULL(cfg); EXPECT_NOT_NULL(cfg);
/* Single-element queues */ /* Single-element queues */
@@ -67,8 +67,8 @@ static void test_sender_queue_capacities() {
/* Test that create handles zero-capacity queues */ /* Test that create handles zero-capacity queues */
static void test_sender_zero_capacity() { static void test_sender_zero_capacity() {
Config* cfg = config_create(str_dup("4.0"), str_dup("/src"), str_dup("/dst"), Config* cfg = config_create(str_dup("4.0"), str_dup("/src"), str_dup("/dst"), false, false, false,
false, false, false, false, false, 0, false, 0); false, false, 0, false, 0);
EXPECT_NOT_NULL(cfg); EXPECT_NOT_NULL(cfg);
Queue* q1 = queue_create(0, NULL); Queue* q1 = queue_create(0, NULL);
@@ -82,8 +82,8 @@ static void test_sender_zero_capacity() {
/* Test receiver with zero file_descriptor */ /* Test receiver with zero file_descriptor */
static void test_receiver_fd_zero() { static void test_receiver_fd_zero() {
Config* cfg = config_create(str_dup("5.0"), str_dup("/src"), str_dup("/dst"), Config* cfg = config_create(str_dup("5.0"), str_dup("/src"), str_dup("/dst"), false, false, false,
false, false, false, false, false, 0, false, 0); false, false, 0, false, 0);
Queue* q = queue_create(5, NULL); Queue* q = queue_create(5, NULL);
PipelineContextReceiver* ctx = pipeline_context_receiver_create(cfg, q, 0); PipelineContextReceiver* ctx = pipeline_context_receiver_create(cfg, q, 0);
EXPECT_NOT_NULL(ctx); EXPECT_NOT_NULL(ctx);
+4 -7
View File
@@ -248,9 +248,6 @@ static void test_scanner_max_size() {
const char* dir = "test_scan_max"; const char* dir = "test_scan_max";
const char* small = "test_scan_max/small.txt"; const char* small = "test_scan_max/small.txt";
const char* large = "test_scan_max/large.txt"; const char* large = "test_scan_max/large.txt";
create_test_file(small, "tiny");
create_test_file(large, "this_content_is_longer_than_ten_chars");
mkdir(dir, 0755); mkdir(dir, 0755);
create_test_file(small, "tiny"); create_test_file(small, "tiny");
create_test_file(large, "this_content_is_longer_than_ten_chars"); create_test_file(large, "this_content_is_longer_than_ten_chars");
@@ -336,10 +333,10 @@ static void test_scanner_size_range() {
static void test_scanner_mixed_patterns() { static void test_scanner_mixed_patterns() {
/* Combine exclude, include, and size filters together */ /* Combine exclude, include, and size filters together */
const char* dir = "test_scan_mixed"; const char* dir = "test_scan_mixed";
const char* a_txt = "test_scan_mixed/a.txt"; /* size ~= 5 */ const char* a_txt = "test_scan_mixed/a.txt"; /* size ~= 5 */
const char* b_bin = "test_scan_mixed/b.bin"; /* size ~= 13 */ const char* b_bin = "test_scan_mixed/b.bin"; /* size ~= 13 */
const char* c_txt = "test_scan_mixed/c.txt"; /* size ~= 5 */ const char* c_txt = "test_scan_mixed/c.txt"; /* size ~= 5 */
const char* d_bak = "test_scan_mixed/d.bak"; /* size ~= 42 */ const char* d_bak = "test_scan_mixed/d.bak"; /* size ~= 42 */
mkdir(dir, 0755); mkdir(dir, 0755);
create_test_file(a_txt, "aaaaa"); create_test_file(a_txt, "aaaaa");