refactor: split monolithic modules and extract shared components
- Remove dead socket.c/socket.h (accumulated duplicate symbols) - Extract compression.h/c (data_compress/decompress from data.c) - Extract io.h/c (low-level I/O from protocol.c) - Extract metadata.h/c (unified metadata wire format from file.c, chunk.c, utils.c) - Split client.c into client_cli.c (CLI parsing) + client_send.c (send logic) - Move receiver pipeline threads from server.c to multiprocessing.c - Move to_disk/file_restore_metadata from utils.c to file.c/metadata.c - Fix const qualifiers on to_disk and str_dup signatures - Suppress chown unused-result warning
This commit is contained in:
+2
-33
@@ -1,12 +1,9 @@
|
||||
#include "utils.h"
|
||||
#include "libgen.h"
|
||||
#include "sys/stat.h"
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
void mkdir_r(char *path) {
|
||||
char *path_duplicate = malloc(strlen(path) + 1);
|
||||
@@ -39,7 +36,7 @@ void mkdir_r(char *path) {
|
||||
free(path_current);
|
||||
}
|
||||
|
||||
char *str_dup(char *string) {
|
||||
char *str_dup(const char *string) {
|
||||
if (string == NULL)
|
||||
return NULL;
|
||||
char *new_string = (char *)malloc(strlen(string) + 1);
|
||||
@@ -47,34 +44,6 @@ char *str_dup(char *string) {
|
||||
return new_string;
|
||||
}
|
||||
|
||||
void to_disk(char *path, void *data, unsigned long long data_size) {
|
||||
char *directory = str_dup(path);
|
||||
char *dir_to_free = directory;
|
||||
directory = dirname(directory);
|
||||
mkdir_r(directory);
|
||||
FILE *file_pointer = fopen(path, "wb");
|
||||
if (file_pointer == NULL) {
|
||||
perror("Could not open File");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
fwrite(data, 1, data_size, file_pointer);
|
||||
fclose(file_pointer);
|
||||
free(dir_to_free);
|
||||
}
|
||||
|
||||
void file_restore_metadata(const char *path, FileMetadata *metadata) {
|
||||
if (metadata == NULL)
|
||||
return;
|
||||
chmod(path, metadata->mode & 07777);
|
||||
chown(path, metadata->uid, metadata->gid);
|
||||
struct timespec times[2];
|
||||
times[0].tv_sec = 0;
|
||||
times[0].tv_nsec = UTIME_OMIT;
|
||||
times[1].tv_sec = metadata->mtime_sec;
|
||||
times[1].tv_nsec = metadata->mtime_nsec;
|
||||
utimensat(AT_FDCWD, path, times, 0);
|
||||
}
|
||||
|
||||
char *path_cat(char *path1, char *path2) {
|
||||
if (path1 == NULL || *path1 == '\0')
|
||||
return str_dup(path2);
|
||||
|
||||
Reference in New Issue
Block a user