Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2dcfad0321 | |||
| 1924fd5157 | |||
| f629ebceb7 | |||
| a968eea712 | |||
| 0bfa68fee7 |
@@ -34,6 +34,7 @@ static void print_usage(void) {
|
|||||||
printf(" --include <pattern> Only include files matching pattern\n");
|
printf(" --include <pattern> Only include files matching pattern\n");
|
||||||
printf(" --max-size <n> Skip files larger than n bytes\n");
|
printf(" --max-size <n> Skip files larger than n bytes\n");
|
||||||
printf(" --min-size <n> Skip files smaller than n bytes\n");
|
printf(" --min-size <n> Skip files smaller than n bytes\n");
|
||||||
|
printf(" --incremental Skip files unchanged since last transfer\n");
|
||||||
printf(" -m Enable multithreading\n");
|
printf(" -m Enable multithreading\n");
|
||||||
printf(" -s Enable chunk serialization\n");
|
printf(" -s Enable chunk serialization\n");
|
||||||
printf(" -f Enable sendfile (TCP only, not with -c or -s)\n");
|
printf(" -f Enable sendfile (TCP only, not with -c or -s)\n");
|
||||||
@@ -93,6 +94,8 @@ int main(int argc, char *argv[]) {
|
|||||||
config->max_size = strtoull(argv[++i], NULL, 10);
|
config->max_size = strtoull(argv[++i], NULL, 10);
|
||||||
} else if (strcmp(argv[i], "--min-size") == 0 && i + 1 < argc) {
|
} else if (strcmp(argv[i], "--min-size") == 0 && i + 1 < argc) {
|
||||||
config->min_size = strtoull(argv[++i], NULL, 10);
|
config->min_size = strtoull(argv[++i], NULL, 10);
|
||||||
|
} else if (strcmp(argv[i], "--incremental") == 0) {
|
||||||
|
config->use_incremental = true;
|
||||||
} else if (strcmp(argv[i], "-c") == 0 || strcmp(argv[i], "-z") == 0) {
|
} else if (strcmp(argv[i], "-c") == 0 || strcmp(argv[i], "-z") == 0) {
|
||||||
config->use_compression = true;
|
config->use_compression = true;
|
||||||
log_message(LOG_LEVEL_INFO, "Enabled Compression");
|
log_message(LOG_LEVEL_INFO, "Enabled Compression");
|
||||||
@@ -202,6 +205,16 @@ int main(int argc, char *argv[]) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (config->use_incremental && config->use_chunk_serialization) {
|
||||||
|
fprintf(stderr, "Error: --incremental is not supported with -s (chunk serialization)\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (config->use_incremental && !config->use_metadata) {
|
||||||
|
log_message(LOG_LEVEL_INFO, "Enabling metadata preservation for --incremental");
|
||||||
|
config->use_metadata = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (config->use_multithreading)
|
if (config->use_multithreading)
|
||||||
return send_files_multithreaded(config);
|
return send_files_multithreaded(config);
|
||||||
return send_files(config);
|
return send_files(config);
|
||||||
|
|||||||
@@ -18,6 +18,27 @@
|
|||||||
#include <threads.h>
|
#include <threads.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
|
static int incremental_check(Client *client, File *file) {
|
||||||
|
if (!send_status(client->file_descriptor, STATUS_CHECK)) return -1;
|
||||||
|
if (!send_str(client->file_descriptor, file->path)) return -1;
|
||||||
|
unsigned long long fsize = file->data->size;
|
||||||
|
long long mtime = file->metadata ? file->metadata->mtime_sec : 0;
|
||||||
|
if (!send_n_data(client->file_descriptor, &fsize, sizeof(fsize))) return -1;
|
||||||
|
if (!send_n_data(client->file_descriptor, &mtime, sizeof(mtime))) return -1;
|
||||||
|
Status s;
|
||||||
|
if (!receive_status(client->file_descriptor, &s)) return -1;
|
||||||
|
if (s == STATUS_ERROR) {
|
||||||
|
log_message(LOG_LEVEL_ERROR, "Server reported error for file");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (s == STATUS_OK) return 1;
|
||||||
|
if (s != STATUS_NEXT) {
|
||||||
|
log_message(LOG_LEVEL_ERROR, "Unexpected server status");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int send_chunk(Client *client, Chunk *chunk, Config *config) {
|
int send_chunk(Client *client, Chunk *chunk, Config *config) {
|
||||||
if (config->use_chunk_serialization) {
|
if (config->use_chunk_serialization) {
|
||||||
if (!send_status(client->file_descriptor, STATUS_CHUNK)) return -1;
|
if (!send_status(client->file_descriptor, STATUS_CHUNK)) return -1;
|
||||||
@@ -32,17 +53,35 @@ int send_chunk(Client *client, Chunk *chunk, Config *config) {
|
|||||||
data_destroy(data);
|
data_destroy(data);
|
||||||
} else if (config->use_sendfile && !config->use_compression) {
|
} else if (config->use_sendfile && !config->use_compression) {
|
||||||
for (int i = 0; i < chunk->element_count; i++) {
|
for (int i = 0; i < chunk->element_count; i++) {
|
||||||
if (!send_status(client->file_descriptor, STATUS_NEXT)) return -1;
|
if (config->use_incremental) {
|
||||||
if (!file_send_sendfile(chunk->items[i], client->file_descriptor, config->use_metadata))
|
int rc = incremental_check(client, chunk->items[i]);
|
||||||
return -1;
|
if (rc < 0) return -1;
|
||||||
|
if (rc > 0) continue;
|
||||||
|
if (!file_send_sendfile(chunk->items[i], client->file_descriptor, config->use_metadata, false))
|
||||||
|
return -1;
|
||||||
|
} else {
|
||||||
|
if (!send_status(client->file_descriptor, STATUS_NEXT)) return -1;
|
||||||
|
if (!file_send_sendfile(chunk->items[i], client->file_descriptor, config->use_metadata, true))
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (int i = 0; i < chunk->element_count; i++) {
|
for (int i = 0; i < chunk->element_count; i++) {
|
||||||
if (!send_status(client->file_descriptor, STATUS_NEXT)) return -1;
|
if (config->use_incremental) {
|
||||||
if (!file_send_single_calls(chunk->items[i], client->file_descriptor,
|
int rc = incremental_check(client, chunk->items[i]);
|
||||||
config->use_metadata,
|
if (rc < 0) return -1;
|
||||||
config->use_compression ? config->compression_level : 0))
|
if (rc > 0) continue;
|
||||||
return -1;
|
if (!file_send_single_calls(chunk->items[i], client->file_descriptor,
|
||||||
|
config->use_metadata,
|
||||||
|
config->use_compression ? config->compression_level : 0, false))
|
||||||
|
return -1;
|
||||||
|
} else {
|
||||||
|
if (!send_status(client->file_descriptor, STATUS_NEXT)) return -1;
|
||||||
|
if (!file_send_single_calls(chunk->items[i], client->file_descriptor,
|
||||||
|
config->use_metadata,
|
||||||
|
config->use_compression ? config->compression_level : 0, true))
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
+60
-2
@@ -16,12 +16,70 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
int receive_files(Config *config, int file_descriptor) {
|
int receive_files(Config *config, int file_descriptor) {
|
||||||
Status status;
|
Status status;
|
||||||
if (!receive_status(file_descriptor, &status)) return -1;
|
if (!receive_status(file_descriptor, &status)) return -1;
|
||||||
while (status == STATUS_NEXT || status == STATUS_CHUNK) {
|
while (status == STATUS_NEXT || status == STATUS_CHUNK || status == STATUS_CHECK) {
|
||||||
if (status == STATUS_CHUNK) {
|
if (status == STATUS_CHECK) {
|
||||||
|
char *check_path = receive_str(file_descriptor);
|
||||||
|
if (check_path == NULL) { send_status(file_descriptor, STATUS_ERROR); return -1; }
|
||||||
|
unsigned long long check_size;
|
||||||
|
long long check_mtime;
|
||||||
|
if (!receive_n_data(file_descriptor, &check_size, sizeof(check_size)) ||
|
||||||
|
!receive_n_data(file_descriptor, &check_mtime, sizeof(check_mtime))) {
|
||||||
|
free(check_path);
|
||||||
|
send_status(file_descriptor, STATUS_ERROR);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
char *full_path = path_cat(config->receive_root_directory, check_path);
|
||||||
|
struct stat st;
|
||||||
|
bool match = false;
|
||||||
|
if (full_path && stat(full_path, &st) == 0 &&
|
||||||
|
(unsigned long long)st.st_size == check_size &&
|
||||||
|
(long long)st.st_mtime == check_mtime) {
|
||||||
|
match = true;
|
||||||
|
}
|
||||||
|
free(full_path);
|
||||||
|
if (match) {
|
||||||
|
if (!send_status(file_descriptor, STATUS_OK)) { free(check_path); return -1; }
|
||||||
|
free(check_path);
|
||||||
|
} else {
|
||||||
|
if (!send_status(file_descriptor, STATUS_NEXT)) { free(check_path); return -1; }
|
||||||
|
File *file = file_create(check_path);
|
||||||
|
free(check_path);
|
||||||
|
if (file == NULL) { send_status(file_descriptor, STATUS_ERROR); return -1; }
|
||||||
|
if (config->use_metadata) {
|
||||||
|
int meta_ok = 1;
|
||||||
|
file->metadata = metadata_receive(file_descriptor, &meta_ok);
|
||||||
|
if (!meta_ok) { file_destroy(file); send_status(file_descriptor, STATUS_ERROR); return -1; }
|
||||||
|
}
|
||||||
|
Data *file_data = receive_data(file_descriptor);
|
||||||
|
if (file_data == NULL) {
|
||||||
|
file_destroy(file);
|
||||||
|
send_status(file_descriptor, STATUS_ERROR);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (config->use_compression) {
|
||||||
|
Data *uncompressed = data_decompress(file_data);
|
||||||
|
data_destroy(file_data);
|
||||||
|
if (uncompressed == NULL) { file_destroy(file); send_status(file_descriptor, STATUS_ERROR); return -1; }
|
||||||
|
file_data = uncompressed;
|
||||||
|
}
|
||||||
|
data_destroy(file->data);
|
||||||
|
file->data = file_data;
|
||||||
|
if (config->save_to_disk) {
|
||||||
|
char *disk_path = path_cat(config->receive_root_directory, file->path);
|
||||||
|
if (disk_path) {
|
||||||
|
to_disk(disk_path, file->data->data, file->data->size);
|
||||||
|
file_restore_metadata(disk_path, file->metadata);
|
||||||
|
free(disk_path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
file_destroy(file);
|
||||||
|
}
|
||||||
|
} else if (status == STATUS_CHUNK) {
|
||||||
Data *chunk_data = receive_data(file_descriptor);
|
Data *chunk_data = receive_data(file_descriptor);
|
||||||
if (chunk_data == NULL) {
|
if (chunk_data == NULL) {
|
||||||
log_message(LOG_LEVEL_ERROR, "Failed to receive chunk data");
|
log_message(LOG_LEVEL_ERROR, "Failed to receive chunk data");
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ Config *config_create(char *version, char *send_directory,
|
|||||||
config->include_count = 0;
|
config->include_count = 0;
|
||||||
config->max_size = 0;
|
config->max_size = 0;
|
||||||
config->min_size = 0;
|
config->min_size = 0;
|
||||||
|
config->use_incremental = false;
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,6 +90,7 @@ bool config_send(int file_descriptor, Config *config) {
|
|||||||
if (!send_int(file_descriptor, (int)config->chunk_size)) return false;
|
if (!send_int(file_descriptor, (int)config->chunk_size)) return false;
|
||||||
if (!send_int(file_descriptor, config->use_sendfile)) return false;
|
if (!send_int(file_descriptor, config->use_sendfile)) return false;
|
||||||
if (!send_int(file_descriptor, config->use_delete)) return false;
|
if (!send_int(file_descriptor, config->use_delete)) return false;
|
||||||
|
if (!send_int(file_descriptor, config->use_incremental)) return false;
|
||||||
Status status;
|
Status status;
|
||||||
if (!receive_status(file_descriptor, &status)) return false;
|
if (!receive_status(file_descriptor, &status)) return false;
|
||||||
if (status != STATUS_OK) {
|
if (status != STATUS_OK) {
|
||||||
@@ -134,6 +136,8 @@ Config *config_receive(int file_descriptor) {
|
|||||||
config->use_sendfile = tmp;
|
config->use_sendfile = tmp;
|
||||||
if (!receive_int(file_descriptor, &tmp)) goto error;
|
if (!receive_int(file_descriptor, &tmp)) goto error;
|
||||||
config->use_delete = tmp;
|
config->use_delete = tmp;
|
||||||
|
if (!receive_int(file_descriptor, &tmp)) goto error;
|
||||||
|
config->use_incremental = tmp;
|
||||||
config->show_progress = false;
|
config->show_progress = false;
|
||||||
config->dry_run = false;
|
config->dry_run = false;
|
||||||
config->ssh_port = 22;
|
config->ssh_port = 22;
|
||||||
|
|||||||
+2
-1
@@ -32,9 +32,10 @@ typedef struct Config {
|
|||||||
int include_count;
|
int include_count;
|
||||||
unsigned long long max_size;
|
unsigned long long max_size;
|
||||||
unsigned long long min_size;
|
unsigned long long min_size;
|
||||||
|
bool use_incremental;
|
||||||
} Config;
|
} Config;
|
||||||
|
|
||||||
#define PROTOCOL_VERSION "1.0.0"
|
#define PROTOCOL_VERSION "1.1.0"
|
||||||
#define DEFAULT_CHUNK_SIZE (10 * 1024 * 1024)
|
#define DEFAULT_CHUNK_SIZE (10 * 1024 * 1024)
|
||||||
|
|
||||||
Config *config_create(char *version, char *send_directory,
|
Config *config_create(char *version, char *send_directory,
|
||||||
|
|||||||
+23
-14
@@ -96,23 +96,30 @@ bool file_load_data(File *file) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool file_send_single_calls(File *file, int file_descriptor, bool use_metadata, int compression_level) {
|
bool file_send_single_calls(File *file, int file_descriptor, bool use_metadata, int compression_level, bool send_path) {
|
||||||
|
Data *data_to_send = file->data;
|
||||||
|
Data *compressed_data = NULL;
|
||||||
if (compression_level > 0) {
|
if (compression_level > 0) {
|
||||||
Data *compressed_data = data_compress(file->data, compression_level);
|
compressed_data = data_compress(file->data, compression_level);
|
||||||
if (compressed_data == NULL) {
|
if (compressed_data == NULL) {
|
||||||
log_message(LOG_LEVEL_ERROR, "Failed to compress file data");
|
log_message(LOG_LEVEL_ERROR, "Failed to compress file data");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
data_destroy(file->data);
|
data_to_send = compressed_data;
|
||||||
if (compressed_data == NULL) {
|
|
||||||
log_message(LOG_LEVEL_ERROR, "Compression failed in file_send_single_calls");
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
file->data = compressed_data;
|
|
||||||
}
|
}
|
||||||
if (!send_str(file_descriptor, file->path)) return false;
|
if (send_path && !send_str(file_descriptor, file->path)) {
|
||||||
if (use_metadata && !metadata_send(file_descriptor, file->metadata)) return false;
|
data_destroy(compressed_data);
|
||||||
if (!send_data(file_descriptor, file->data)) return false;
|
return false;
|
||||||
|
}
|
||||||
|
if (use_metadata && !metadata_send(file_descriptor, file->metadata)) {
|
||||||
|
data_destroy(compressed_data);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!send_data(file_descriptor, data_to_send)) {
|
||||||
|
data_destroy(compressed_data);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
data_destroy(compressed_data);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,8 +148,8 @@ bool to_disk(const char *path, const void *data, unsigned long long data_size) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool file_send_sendfile(File *file, int file_descriptor, bool use_metadata) {
|
bool file_send_sendfile(File *file, int file_descriptor, bool use_metadata, bool send_path) {
|
||||||
if (!send_str(file_descriptor, file->path)) return false;
|
if (send_path && !send_str(file_descriptor, file->path)) return false;
|
||||||
if (use_metadata && !metadata_send(file_descriptor, file->metadata)) return false;
|
if (use_metadata && !metadata_send(file_descriptor, file->metadata)) return false;
|
||||||
|
|
||||||
int fd = open(file->path, O_RDONLY);
|
int fd = open(file->path, O_RDONLY);
|
||||||
@@ -178,7 +185,9 @@ File *file_receive(Config *config, int file_descriptor) {
|
|||||||
free(path);
|
free(path);
|
||||||
if (file == NULL) return NULL;
|
if (file == NULL) return NULL;
|
||||||
if (config->use_metadata) {
|
if (config->use_metadata) {
|
||||||
file->metadata = metadata_receive(file_descriptor);
|
int meta_ok = 1;
|
||||||
|
file->metadata = metadata_receive(file_descriptor, &meta_ok);
|
||||||
|
if (!meta_ok) { 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) {
|
||||||
|
|||||||
+2
-2
@@ -24,8 +24,8 @@ File *file_create(const char *path);
|
|||||||
void file_destroy(void *item);
|
void file_destroy(void *item);
|
||||||
bool file_load_data(File *file);
|
bool file_load_data(File *file);
|
||||||
File *file_receive(Config *config, int file_descriptor);
|
File *file_receive(Config *config, int file_descriptor);
|
||||||
bool file_send_single_calls(File *file, int file_descriptor, bool use_metadata, int compression_level);
|
bool file_send_single_calls(File *file, int file_descriptor, bool use_metadata, int compression_level, bool send_path);
|
||||||
bool file_send_sendfile(File *file, int file_descriptor, bool use_metadata);
|
bool file_send_sendfile(File *file, int file_descriptor, bool use_metadata, bool send_path);
|
||||||
size_t file_content_to_buffer(File *file);
|
size_t file_content_to_buffer(File *file);
|
||||||
FileMetadata *file_metadata_create(struct stat *stats);
|
FileMetadata *file_metadata_create(struct stat *stats);
|
||||||
void file_metadata_destroy(void *metadata);
|
void file_metadata_destroy(void *metadata);
|
||||||
|
|||||||
+10
-4
@@ -50,22 +50,28 @@ bool metadata_send(int file_descriptor, FileMetadata *m) {
|
|||||||
send_n_data(file_descriptor, &m->mtime_nsec, sizeof(long));
|
send_n_data(file_descriptor, &m->mtime_nsec, sizeof(long));
|
||||||
}
|
}
|
||||||
|
|
||||||
FileMetadata *metadata_receive(int file_descriptor) {
|
FileMetadata *metadata_receive(int file_descriptor, int *ok) {
|
||||||
int present;
|
int present;
|
||||||
if (!receive_n_data(file_descriptor, &present, sizeof(int)))
|
if (!receive_n_data(file_descriptor, &present, sizeof(int))) {
|
||||||
|
if (ok) *ok = 0;
|
||||||
return NULL;
|
return NULL;
|
||||||
if (!present)
|
}
|
||||||
|
if (!present) {
|
||||||
|
if (ok) *ok = 1;
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
FileMetadata *m = malloc(sizeof(FileMetadata));
|
FileMetadata *m = malloc(sizeof(FileMetadata));
|
||||||
if (m == NULL) return NULL;
|
if (m == NULL) { if (ok) *ok = 0; return NULL; }
|
||||||
if (!receive_n_data(file_descriptor, &m->mode, sizeof(mode_t)) ||
|
if (!receive_n_data(file_descriptor, &m->mode, sizeof(mode_t)) ||
|
||||||
!receive_n_data(file_descriptor, &m->uid, sizeof(uid_t)) ||
|
!receive_n_data(file_descriptor, &m->uid, sizeof(uid_t)) ||
|
||||||
!receive_n_data(file_descriptor, &m->gid, sizeof(gid_t)) ||
|
!receive_n_data(file_descriptor, &m->gid, sizeof(gid_t)) ||
|
||||||
!receive_n_data(file_descriptor, &m->mtime_sec, sizeof(time_t)) ||
|
!receive_n_data(file_descriptor, &m->mtime_sec, sizeof(time_t)) ||
|
||||||
!receive_n_data(file_descriptor, &m->mtime_nsec, sizeof(long))) {
|
!receive_n_data(file_descriptor, &m->mtime_nsec, sizeof(long))) {
|
||||||
free(m);
|
free(m);
|
||||||
|
if (ok) *ok = 0;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
if (ok) *ok = 1;
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
void metadata_to_buf(char **buf, FileMetadata *m);
|
void metadata_to_buf(char **buf, FileMetadata *m);
|
||||||
FileMetadata *metadata_from_buf(char **buf);
|
FileMetadata *metadata_from_buf(char **buf);
|
||||||
bool metadata_send(int file_descriptor, FileMetadata *m);
|
bool metadata_send(int file_descriptor, FileMetadata *m);
|
||||||
FileMetadata *metadata_receive(int file_descriptor);
|
FileMetadata *metadata_receive(int file_descriptor, int *ok);
|
||||||
void file_restore_metadata(const char *path, FileMetadata *metadata);
|
void file_restore_metadata(const char *path, FileMetadata *metadata);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
#include <threads.h>
|
#include <threads.h>
|
||||||
|
|
||||||
PipelineContextSender *pipeline_context_sender_create(Config *config,
|
PipelineContextSender *pipeline_context_sender_create(Config *config,
|
||||||
@@ -126,8 +127,59 @@ int receive_thread(void *pipeline_context) {
|
|||||||
|
|
||||||
Status status;
|
Status status;
|
||||||
if (!receive_status(file_descriptor, &status)) return thrd_error;
|
if (!receive_status(file_descriptor, &status)) return thrd_error;
|
||||||
while (status == STATUS_NEXT || status == STATUS_CHUNK) {
|
while (status == STATUS_NEXT || status == STATUS_CHUNK || status == STATUS_CHECK) {
|
||||||
if (status == STATUS_CHUNK) {
|
if (status == STATUS_CHECK) {
|
||||||
|
char *check_path = receive_str(file_descriptor);
|
||||||
|
if (check_path == NULL) { send_status(file_descriptor, STATUS_ERROR); return thrd_error; }
|
||||||
|
unsigned long long check_size;
|
||||||
|
long long check_mtime;
|
||||||
|
if (!receive_n_data(file_descriptor, &check_size, sizeof(check_size)) ||
|
||||||
|
!receive_n_data(file_descriptor, &check_mtime, sizeof(check_mtime))) {
|
||||||
|
free(check_path);
|
||||||
|
send_status(file_descriptor, STATUS_ERROR);
|
||||||
|
return thrd_error;
|
||||||
|
}
|
||||||
|
char *full_path = path_cat(config->receive_root_directory, check_path);
|
||||||
|
struct stat st;
|
||||||
|
bool match = false;
|
||||||
|
if (full_path && stat(full_path, &st) == 0 &&
|
||||||
|
(unsigned long long)st.st_size == check_size &&
|
||||||
|
(long long)st.st_mtime == check_mtime) {
|
||||||
|
match = true;
|
||||||
|
}
|
||||||
|
free(full_path);
|
||||||
|
if (match) {
|
||||||
|
if (!send_status(file_descriptor, STATUS_OK)) { free(check_path); return thrd_error; }
|
||||||
|
free(check_path);
|
||||||
|
} else {
|
||||||
|
if (!send_status(file_descriptor, STATUS_NEXT)) { free(check_path); return thrd_error; }
|
||||||
|
File *file = file_create(check_path);
|
||||||
|
free(check_path);
|
||||||
|
if (file == NULL) { send_status(file_descriptor, STATUS_ERROR); return thrd_error; }
|
||||||
|
if (config->use_metadata) {
|
||||||
|
int meta_ok = 1;
|
||||||
|
file->metadata = metadata_receive(file_descriptor, &meta_ok);
|
||||||
|
if (!meta_ok) { file_destroy(file); send_status(file_descriptor, STATUS_ERROR); return thrd_error; }
|
||||||
|
}
|
||||||
|
Data *file_data = receive_data(file_descriptor);
|
||||||
|
if (file_data == NULL) {
|
||||||
|
file_destroy(file);
|
||||||
|
send_status(file_descriptor, STATUS_ERROR);
|
||||||
|
return thrd_error;
|
||||||
|
}
|
||||||
|
if (config->use_compression) {
|
||||||
|
Data *uncompressed = data_decompress(file_data);
|
||||||
|
data_destroy(file_data);
|
||||||
|
if (uncompressed == NULL) { file_destroy(file); send_status(file_descriptor, STATUS_ERROR); return thrd_error; }
|
||||||
|
file_data = uncompressed;
|
||||||
|
}
|
||||||
|
data_destroy(file->data);
|
||||||
|
file->data = file_data;
|
||||||
|
queue_enqueue_multithreaded(context->queue, file, &context->mutex,
|
||||||
|
&context->condition_not_empty,
|
||||||
|
&context->condition_not_full);
|
||||||
|
}
|
||||||
|
} else if (status == STATUS_CHUNK) {
|
||||||
receive_chunk_enqueue(file_descriptor, context);
|
receive_chunk_enqueue(file_descriptor, context);
|
||||||
} else {
|
} else {
|
||||||
File *file = file_receive(config, file_descriptor);
|
File *file = file_receive(config, file_descriptor);
|
||||||
|
|||||||
@@ -111,6 +111,8 @@ static const char *status_to_string(Status status) {
|
|||||||
return "NEXT";
|
return "NEXT";
|
||||||
case STATUS_CHUNK:
|
case STATUS_CHUNK:
|
||||||
return "CHUNK";
|
return "CHUNK";
|
||||||
|
case STATUS_CHECK:
|
||||||
|
return "CHECK";
|
||||||
default:
|
default:
|
||||||
return "UNKNOWN";
|
return "UNKNOWN";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
typedef int Status;
|
typedef int Status;
|
||||||
enum NET_STATUS { STATUS_OK, STATUS_ERROR, STATUS_FINISHED, STATUS_NEXT, STATUS_CHUNK, STATUS_MANIFEST };
|
enum NET_STATUS { STATUS_OK, STATUS_ERROR, STATUS_FINISHED, STATUS_NEXT, STATUS_CHUNK, STATUS_MANIFEST, STATUS_CHECK };
|
||||||
|
|
||||||
void io_set_fds(int read_fd, int write_fd);
|
void io_set_fds(int read_fd, int write_fd);
|
||||||
void io_set_bwlimit(unsigned long long bytes_per_sec);
|
void io_set_bwlimit(unsigned long long bytes_per_sec);
|
||||||
|
|||||||
@@ -394,6 +394,33 @@ def run_profile(profile_name, source_dir, dest_dir):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
results.append({"name": "Bandwidth limit (--bwlimit 10240)", "suite": profile_name, "status": "Error", "time": "N/A", "error": str(e)})
|
results.append({"name": "Bandwidth limit (--bwlimit 10240)", "suite": profile_name, "status": "Error", "time": "N/A", "error": str(e)})
|
||||||
|
|
||||||
|
# Incremental sync (--incremental) — first sync, then second sync should skip all
|
||||||
|
print(f"\n --- Incremental (--incremental) ---")
|
||||||
|
try:
|
||||||
|
flags = BASE_CLIENT_FLAGS + ["-M"]
|
||||||
|
srv = subprocess.Popen(SERVER_CMD, stdout=subprocess.DEVNULL, stderr=None)
|
||||||
|
time.sleep(0.5)
|
||||||
|
first_cmd = client_prefix + BASE_CLIENT_CMD + ["--source-dir", source_dir, "--dest-dir", dest_dir] + flags
|
||||||
|
r1 = subprocess.run(first_cmd, text=True, capture_output=True)
|
||||||
|
wait_proc(srv)
|
||||||
|
if r1.returncode != 0:
|
||||||
|
raise RuntimeError(f"First sync failed: {r1.stderr[:100]}")
|
||||||
|
srv2 = subprocess.Popen(SERVER_CMD, stdout=subprocess.DEVNULL, stderr=None)
|
||||||
|
time.sleep(0.5)
|
||||||
|
second_cmd = client_prefix + BASE_CLIENT_CMD + ["--source-dir", source_dir, "--dest-dir", dest_dir] + flags + ["--incremental"]
|
||||||
|
start = time.monotonic()
|
||||||
|
r2 = subprocess.run(second_cmd, text=True, capture_output=True, timeout=30)
|
||||||
|
duration = time.monotonic() - start
|
||||||
|
wait_proc(srv2)
|
||||||
|
r = {"name": "Incremental (--incremental)", "suite": profile_name,
|
||||||
|
"status": "Success" if r2.returncode == 0 else "Failed",
|
||||||
|
"time": f"{duration:.4f}s" if r2.returncode == 0 else "N/A",
|
||||||
|
"error": "" if r2.returncode == 0 else f"Exit {r2.returncode}: {(r2.stderr or r2.stdout)[:60]}"}
|
||||||
|
results.append(r)
|
||||||
|
except Exception as e:
|
||||||
|
results.append({"name": "Incremental (--incremental)", "suite": profile_name,
|
||||||
|
"status": "Error", "time": "N/A", "error": str(e)})
|
||||||
|
|
||||||
# Chunk size (--chunk-size 5242880)
|
# Chunk size (--chunk-size 5242880)
|
||||||
feature_flags = BASE_CLIENT_FLAGS + ["--chunk-size", "5242880"]
|
feature_flags = BASE_CLIENT_FLAGS + ["--chunk-size", "5242880"]
|
||||||
cmd = client_prefix + BASE_CLIENT_CMD + ["--source-dir", source_dir, "--dest-dir", dest_dir] + feature_flags
|
cmd = client_prefix + BASE_CLIENT_CMD + ["--source-dir", source_dir, "--dest-dir", dest_dir] + feature_flags
|
||||||
|
|||||||
Reference in New Issue
Block a user