From f5fc8b588f6f030dc3e1973021456d15ce4a2bcf Mon Sep 17 00:00:00 2001 From: Chewing_Bever Date: Tue, 6 Jun 2023 20:12:42 +0200 Subject: [PATCH] feat: properly backup config directory --- .cargo/config.toml | 1 + src/server/process.rs | 28 +++++++++++++++++++--------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/.cargo/config.toml b/.cargo/config.toml index 711c41b..d1675c8 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,2 +1,3 @@ [alias] runs = "run -- paper 1.19.4-545 --config data/config --backup data/backups --world data/worlds --jar data/paper.jar" +runrs = "run --release -- paper 1.19.4-545 --config data/config --backup data/backups --world data/worlds --jar data/paper.jar" diff --git a/src/server/process.rs b/src/server/process.rs index 2b6f6fa..5640b18 100644 --- a/src/server/process.rs +++ b/src/server/process.rs @@ -2,7 +2,7 @@ use crate::server::ServerType; use flate2::write::GzEncoder; use flate2::Compression; use std::io::Write; -use std::path::PathBuf; +use std::path::{Path, PathBuf}; use std::process::Child; #[link(name = "c")] @@ -108,11 +108,21 @@ impl ServerProcess { tar.append_dir_all("worlds", &self.world_dir)?; - // We don't store all files in the config, as this would include caches - tar.append_path_with_name( - self.config_dir.join("server.properties"), - "config/server.properties", - )?; + // Add all files from the config directory that aren't the cache + for entry in self + .config_dir + .read_dir()? + .filter_map(|e| e.ok()) + .filter(|e| e.file_name() != "cache") + { + let tar_path = Path::new("config").join(entry.file_name()); + + if entry.file_type()?.is_dir() { + tar.append_dir_all(tar_path, entry.path())?; + } else { + tar.append_path_with_name(entry.path(), tar_path)?; + } + } // We add a file to the backup describing for what version it was made let info = format!("{} {}", self.type_, self.version); @@ -128,8 +138,6 @@ impl ServerProcess { tar.append_data(&mut header, "info.txt", info_bytes)?; - // tar.append_dir_all("config", &self.config_dir)?; - // Backup file gets finalized in the drop Ok(()) @@ -139,7 +147,9 @@ impl ServerProcess { fn remove_old_backups(&mut self) -> std::io::Result<()> { // The naming format used allows us to sort the backups by name and still get a sorting by // creation time - let mut backups = std::fs::read_dir(&self.backup_dir)? + let mut backups = self + .backup_dir + .read_dir()? .filter_map(|res| res.map(|e| e.path()).ok()) .collect::>(); backups.sort();