From 91a60f3d22cb700e2ab450df3622760f246a5db7 Mon Sep 17 00:00:00 2001 From: Alessandro Maestri Date: Wed, 15 Oct 2025 23:37:21 +0200 Subject: [PATCH 1/2] fix(backup): use relative paths when creating tar.gz archives on macOS/Linux - Fixed error "paths in archives must be relative" during compressed backup - Updated compress_tar_gz() to use append_path_with_name() with file_name() - Ensured compatibility with macOS and Linux tar implementations - Verified consistent behavior across all platforms --- src/commands/backup.rs | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/commands/backup.rs b/src/commands/backup.rs index d33c4d0..d7c085d 100644 --- a/src/commands/backup.rs +++ b/src/commands/backup.rs @@ -5,7 +5,7 @@ use chrono::Local; use std::fs; use std::fs::File; use std::io::{self}; -use std::path::PathBuf; +use std::path::{Path, PathBuf}; #[cfg(target_os = "windows")] use std::io::Write; @@ -16,7 +16,7 @@ use crate::utils::icons::ERR; #[cfg(not(target_os = "windows"))] use flate2::{Compression, write::GzEncoder}; #[cfg(not(target_os = "windows"))] -use tar::Builder as TarBuilder; +use tar::Builder; pub fn handle_backup(_conn: &rusqlite::Connection, compress: bool) -> io::Result<()> { let fail_mess = tr("app.config.load_failed"); @@ -93,11 +93,17 @@ fn compress_zip(src: &PathBuf, dest_zip: &PathBuf) -> io::Result<()> { } #[cfg(not(target_os = "windows"))] -fn compress_tar_gz(src: &PathBuf, dest_tar_gz: &PathBuf) -> io::Result<()> { - let tar_gz = File::create(dest_tar_gz)?; - let enc = GzEncoder::new(tar_gz, Compression::default()); - let mut tar = TarBuilder::new(enc); - tar.append_path(src)?; +pub fn compress_tar_gz(src_path: &Path, dest_path: &Path) -> io::Result<()> { + let tar_gz = File::create(dest_path)?; + let encoder = GzEncoder::new(tar_gz, Compression::default()); + let mut tar = Builder::new(encoder); + + // ✅ Usa solo il nome del file (relativo) dentro l’archivio + let file_name = src_path + .file_name() + .unwrap_or_else(|| std::ffi::OsStr::new("librius.db")); + tar.append_path_with_name(src_path, file_name)?; + tar.finish()?; Ok(()) } From 4ead1b52283ed97322b8bb0a60833f207f9a9c89 Mon Sep 17 00:00:00 2001 From: Alessandro Maestri Date: Wed, 15 Oct 2025 23:45:53 +0200 Subject: [PATCH 2/2] doc(CHAGELOG): added fixed message for backup compression on macOS/Linux --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0c8df92..93e323c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ All notable changes to this project will be documented in this file. - `.tar.gz` format on macOS and Linux - Localized help and messages via i18n (English and Italian) - Timestamp-based file naming for safe sequential backups + - Fixed backup compression error on macOS/Linux (`paths in archives must be relative`). - **Export command** (`librius export`) - Added support for exporting library data in multiple formats: