Merge remaining 4 PRs: memory safety, refactoring, test coverage, integration cleanup #93
@@ -118,6 +118,11 @@ bool file_send_single_calls(File* file, int file_descriptor, bool use_metadata,
|
||||
data_destroy(compressed_data);
|
||||
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)) {
|
||||
data_destroy(compressed_data);
|
||||
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);
|
||||
if (file_data == NULL) {
|
||||
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))
|
||||
return false;
|
||||
|
||||
int ft = 0; // FILE_TYPE_REGULAR
|
||||
if (!send_int(file_descriptor, ft))
|
||||
return false;
|
||||
|
||||
int fd = open(file->path, O_RDONLY);
|
||||
if (fd == -1) {
|
||||
perror("Could not open file for sendfile");
|
||||
@@ -504,6 +520,11 @@ File* file_receive(const Config* config, int file_descriptor) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
int file_type;
|
||||
if (!receive_int(file_descriptor, &file_type)) {
|
||||
file_destroy(file);
|
||||
return NULL;
|
||||
}
|
||||
Data* file_data = receive_data(file_descriptor);
|
||||
if (file_data == NULL) {
|
||||
file_destroy(file);
|
||||
|
||||
@@ -217,6 +217,9 @@ static void test_file_send_no_path() {
|
||||
pid_t pid = fork();
|
||||
if (pid == 0) {
|
||||
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]);
|
||||
close(p[0]);
|
||||
|
||||
|
||||
@@ -22,8 +22,8 @@ static void test_sendfile_basic() {
|
||||
/* Set the size so file_send_sendfile can report it */
|
||||
file->data->size = len;
|
||||
|
||||
Config* cfg = config_create(str_dup(PROTOCOL_VERSION), str_dup("/tmp"), str_dup("/tmp"),
|
||||
false, false, false, false, false, 0, false, 0);
|
||||
Config* cfg = config_create(str_dup(PROTOCOL_VERSION), str_dup("/tmp"), str_dup("/tmp"), false,
|
||||
false, false, false, false, 0, false, 0);
|
||||
EXPECT_NOT_NULL(cfg);
|
||||
|
||||
int p[2];
|
||||
@@ -80,8 +80,8 @@ static void test_sendfile_empty_file() {
|
||||
EXPECT_NOT_NULL(file);
|
||||
file->data->size = 0;
|
||||
|
||||
Config* cfg = config_create(str_dup(PROTOCOL_VERSION), str_dup("/tmp"), str_dup("/tmp"),
|
||||
false, false, false, false, false, 0, false, 0);
|
||||
Config* cfg = config_create(str_dup(PROTOCOL_VERSION), str_dup("/tmp"), str_dup("/tmp"), false,
|
||||
false, false, false, false, 0, false, 0);
|
||||
EXPECT_NOT_NULL(cfg);
|
||||
|
||||
int p[2];
|
||||
@@ -161,8 +161,8 @@ static void test_sendfile_compression_fallback() {
|
||||
file->data->size = (size_t)st.st_size;
|
||||
EXPECT_TRUE(file_load_data(file));
|
||||
|
||||
Config* cfg = config_create(str_dup(PROTOCOL_VERSION), str_dup("/tmp"), str_dup("/tmp"),
|
||||
false, false, false, true, false, 3, false, 0);
|
||||
Config* cfg = config_create(str_dup(PROTOCOL_VERSION), str_dup("/tmp"), str_dup("/tmp"), false,
|
||||
false, false, true, false, 3, false, 0);
|
||||
EXPECT_NOT_NULL(cfg);
|
||||
|
||||
int p[2];
|
||||
@@ -224,8 +224,11 @@ static void test_sendfile_no_path() {
|
||||
pid_t pid = fork();
|
||||
if (pid == 0) {
|
||||
close(p[1]);
|
||||
/* When send_path is false, the sender sends raw data (size + bytes) only.
|
||||
* We need to receive just the Data, not a File. */
|
||||
/* When send_path is false, the sender sends file_type + raw data (size + bytes).
|
||||
* 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]);
|
||||
close(p[0]);
|
||||
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
|
||||
/* Test pipeline_context_sender_create/destroy with valid arguments */
|
||||
static void test_sender_create_destroy() {
|
||||
Config* cfg = config_create(str_dup("1.0"), str_dup("/src"), str_dup("/dst"),
|
||||
false, false, false, false, false, 0, false, 0);
|
||||
Config* cfg = config_create(str_dup("1.0"), str_dup("/src"), str_dup("/dst"), false, false, false,
|
||||
false, false, 0, false, 0);
|
||||
EXPECT_NOT_NULL(cfg);
|
||||
|
||||
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 */
|
||||
static void test_receiver_create_destroy() {
|
||||
Config* cfg = config_create(str_dup("2.0"), str_dup("/src"), str_dup("/dst"),
|
||||
true, true, false, false, false, 0, false, 0);
|
||||
Config* cfg = config_create(str_dup("2.0"), str_dup("/src"), str_dup("/dst"), true, true, false,
|
||||
false, false, 0, false, 0);
|
||||
EXPECT_NOT_NULL(cfg);
|
||||
|
||||
Queue* q = queue_create(20, NULL);
|
||||
@@ -51,8 +51,8 @@ static void test_receiver_create_destroy() {
|
||||
|
||||
/* Test that create handles various queue capacities */
|
||||
static void test_sender_queue_capacities() {
|
||||
Config* cfg = config_create(str_dup("3.0"), str_dup("/src"), str_dup("/dst"),
|
||||
false, false, false, false, false, 0, false, 0);
|
||||
Config* cfg = config_create(str_dup("3.0"), str_dup("/src"), str_dup("/dst"), false, false, false,
|
||||
false, false, 0, false, 0);
|
||||
EXPECT_NOT_NULL(cfg);
|
||||
|
||||
/* Single-element queues */
|
||||
@@ -67,8 +67,8 @@ static void test_sender_queue_capacities() {
|
||||
|
||||
/* Test that create handles zero-capacity queues */
|
||||
static void test_sender_zero_capacity() {
|
||||
Config* cfg = config_create(str_dup("4.0"), str_dup("/src"), str_dup("/dst"),
|
||||
false, false, false, false, false, 0, false, 0);
|
||||
Config* cfg = config_create(str_dup("4.0"), str_dup("/src"), str_dup("/dst"), false, false, false,
|
||||
false, false, 0, false, 0);
|
||||
EXPECT_NOT_NULL(cfg);
|
||||
|
||||
Queue* q1 = queue_create(0, NULL);
|
||||
@@ -82,8 +82,8 @@ static void test_sender_zero_capacity() {
|
||||
|
||||
/* Test receiver with zero file_descriptor */
|
||||
static void test_receiver_fd_zero() {
|
||||
Config* cfg = config_create(str_dup("5.0"), str_dup("/src"), str_dup("/dst"),
|
||||
false, false, false, false, false, 0, false, 0);
|
||||
Config* cfg = config_create(str_dup("5.0"), str_dup("/src"), str_dup("/dst"), false, false, false,
|
||||
false, false, 0, false, 0);
|
||||
Queue* q = queue_create(5, NULL);
|
||||
PipelineContextReceiver* ctx = pipeline_context_receiver_create(cfg, q, 0);
|
||||
EXPECT_NOT_NULL(ctx);
|
||||
|
||||
@@ -248,9 +248,6 @@ static void test_scanner_max_size() {
|
||||
const char* dir = "test_scan_max";
|
||||
const char* small = "test_scan_max/small.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);
|
||||
create_test_file(small, "tiny");
|
||||
create_test_file(large, "this_content_is_longer_than_ten_chars");
|
||||
|
||||
Reference in New Issue
Block a user