Do not compress rotated files - they are not expected to be large

Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
DL6ER
2023-11-19 22:38:45 +01:00
parent ef679f2edb
commit 98f7ff8e62
3 changed files with 1 additions and 47 deletions
+1 -1
View File
@@ -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))
{
-45
View File
@@ -26,8 +26,6 @@
#include <sys/statvfs.h>
// dirname()
#include <libgen.h>
// compression functions
#include "zip/gzip.h"
// sendfile()
#include <fcntl.h>
#include <sys/sendfile.h>
@@ -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);
}
}
-1
View File
@@ -15,7 +15,6 @@
// setmntent()
#include <mntent.h>
#define PLAIN_ROTATIONS 3
#define MAX_ROTATIONS 15
#define BACKUP_DIR "/etc/pihole/config_backups"