From 98f7ff8e626b7aa75a5abb60e835ffd2c3ccc1ed Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sun, 19 Nov 2023 22:38:45 +0100 Subject: [PATCH] Do not compress rotated files - they are not expected to be large Signed-off-by: DL6ER --- src/config/config.c | 2 +- src/files.c | 45 --------------------------------------------- src/files.h | 1 - 3 files changed, 1 insertion(+), 47 deletions(-) diff --git a/src/config/config.c b/src/config/config.c index 9b086908..fc0ce3ce 100644 --- a/src/config/config.c +++ b/src/config/config.c @@ -1344,7 +1344,7 @@ void readFTLconf(struct config *conf, const bool rewrite) // If we cannot parse /etc/pihole.toml (due to missing or invalid syntax), // we try to read the rotated files in /etc/pihole/config_backup starting at // the most recent one and going back in time until we find a valid config - for(unsigned int i = 0; i < PLAIN_ROTATIONS; i++) + for(unsigned int i = 0; i < MAX_ROTATIONS; i++) { if(readFTLtoml(NULL, conf, NULL, rewrite, NULL, i)) { diff --git a/src/files.c b/src/files.c index f011b585..3c15891b 100644 --- a/src/files.c +++ b/src/files.c @@ -26,8 +26,6 @@ #include // dirname() #include -// compression functions -#include "zip/gzip.h" // sendfile() #include #include @@ -463,14 +461,6 @@ void rotate_files(const char *path, char **first_file) if(i == 1 && first_file != NULL) *first_file = strdup(new_path); - size_t old_path_len = strlen(old_path) + 4; - char *old_path_compressed = calloc(old_path_len, sizeof(char)); - snprintf(old_path_compressed, old_path_len, "%s.gz", old_path); - - size_t new_path_len = strlen(new_path) + 4; - char *new_path_compressed = calloc(new_path_len, sizeof(char)); - snprintf(new_path_compressed, new_path_len, "%s.gz", new_path); - if(file_exists(old_path)) { // Copy file to backup directory @@ -505,46 +495,11 @@ void rotate_files(const char *path, char **first_file) // Change ownership of file to pihole user chown_pihole(new_path); - - // Compress file if we are rotating a sufficiently old file - if(i > PLAIN_ROTATIONS) - { - log_debug(DEBUG_CONFIG, "Compressing %s -> %s", - new_path, new_path_compressed); - if(deflate_file(new_path, new_path_compressed, false)) - { - // On success, we remove the uncompressed file - remove(new_path); - } - - // Change ownership of file to pihole user - chown_pihole(new_path_compressed); - } - } - else if(file_exists(old_path_compressed)) - { - // Rename file - if(rename(old_path_compressed, new_path_compressed) < 0) - { - log_warn("Rotation %s -(MOVE)> %s failed: %s", - old_path_compressed, new_path_compressed, strerror(errno)); - } - else - { - // Log success if debug is enabled - log_debug(DEBUG_CONFIG, "Rotated %s -> %s", - old_path_compressed, new_path_compressed); - } - - // Change ownership of file to pihole user - chown_pihole(new_path_compressed); } // Free memory free(old_path); free(new_path); - free(old_path_compressed); - free(new_path_compressed); } } diff --git a/src/files.h b/src/files.h index 0482cca4..555e5ac0 100644 --- a/src/files.h +++ b/src/files.h @@ -15,7 +15,6 @@ // setmntent() #include -#define PLAIN_ROTATIONS 3 #define MAX_ROTATIONS 15 #define BACKUP_DIR "/etc/pihole/config_backups"