summary history branches tags files
commit:55789ff98e9aed6dc1da3d3f93962cbef9ecaac5
author:Trevor Bentley
committer:Trevor Bentley
date:Mon Jan 13 23:59:41 2025 +0100
parents:b5c7f89959cef58132603b4cb025df1ee1778460
better error chaining
diff --git a/Cargo.lock b/Cargo.lock
line changes: +50/-0
index 57ac26a..15f4af5
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -367,6 +367,18 @@ dependencies = [
 ]
 
 [[package]]
+name = "filetime"
+version = "0.2.19"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4e884668cd0c7480504233e951174ddc3b382f7c2666e3b7310b5c4e7b0c37f9"
+dependencies = [
+ "cfg-if",
+ "libc",
+ "redox_syscall",
+ "windows-sys",
+]
+
+[[package]]
 name = "flate2"
 version = "1.0.25"
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -437,6 +449,12 @@ dependencies = [
 ]
 
 [[package]]
+name = "glob"
+version = "0.3.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b"
+
+[[package]]
 name = "globset"
 version = "0.4.10"
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -582,12 +600,15 @@ version = "0.5.1"
 dependencies = [
  "chrono",
  "clap",
+ "flate2",
  "git2",
+ "glob",
  "open",
  "pulldown-cmark",
  "rayon",
  "serde",
  "syntect",
+ "tar",
  "tera",
  "toml",
 ]
@@ -1054,6 +1075,15 @@ dependencies = [
 ]
 
 [[package]]
+name = "redox_syscall"
+version = "0.2.16"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a"
+dependencies = [
+ "bitflags",
+]
+
+[[package]]
 name = "regex"
 version = "1.7.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1216,6 +1246,17 @@ dependencies = [
 ]
 
 [[package]]
+name = "tar"
+version = "0.4.38"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4b55807c0344e1e6c04d7c965f5289c39a8d94ae23ed5c0b57aabac549f871c6"
+dependencies = [
+ "filetime",
+ "libc",
+ "xattr",
+]
+
+[[package]]
 name = "tera"
 version = "1.17.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1633,6 +1674,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5"
 
 [[package]]
+name = "xattr"
+version = "0.2.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6d1526bbe5aaeb5eb06885f4d987bcdfa5e23187055de9b83fe00156a821fabc"
+dependencies = [
+ "libc",
+]
+
+[[package]]
 name = "xml-rs"
 version = "0.8.4"
 source = "registry+https://github.com/rust-lang/crates.io-index"

diff --git a/Cargo.toml b/Cargo.toml
line changes: +5/-0
index d0d4cbc..2c34d89
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -21,6 +21,7 @@ highlight = ["syntect/default-fancy"]
 chrono = { version = "0.4.23", features=["clock"] }
 clap = { version="4.0.32", features=["derive"] }
 git2 = "0.15.0"
+glob = "0.3.1"
 open = "3.2.0"
 pulldown-cmark = { version = "0.9.2", optional = true }
 rayon = "1.6.1"
@@ -32,3 +33,7 @@ toml = "0.5.10"
 # For SSH passphrase support:
 #pinentry = "0.5.0"
 #secrecy = "0.8.0"
+
+[dev-dependencies]
+flate2 = "1.0.25"
+tar = "0.4.38"

diff --git a/src/util.rs b/src/util.rs
line changes: +12/-4
index 0b08000..d68e18d
--- a/src/util.rs
+++ b/src/util.rs
@@ -20,6 +20,8 @@
  * You should have received a copy of the GNU General Public License
  * along with Itsy-Gitsy.  If not, see <http://www.gnu.org/licenses/>.
  */
+use glob::glob;
+use std::error::Error as StdError;
 use std::path::Path;
 use std::path::PathBuf;
 use std::sync::atomic::AtomicUsize;
@@ -83,6 +85,7 @@ pub enum GitsyErrorKind {
     Settings,
     Template,
     Git,
+    Filesystem,
 }
 
 #[derive(Default)]
@@ -126,9 +129,14 @@ impl std::fmt::Display for GitsyError {
             GitsyErrorKind::Git => write!(f, "gitsy error (git)")?,
             GitsyErrorKind::Settings => write!(f, "gitsy error (settings)")?,
             GitsyErrorKind::Template => write!(f, "gitsy error (template)")?,
-            _ => write!(f, "gitsy error (unknown)")?,
+            GitsyErrorKind::Filesystem => write!(f, "gitsy error (filesystem)")?,
+            GitsyErrorKind::Unknown => write!(f, "gitsy error (unknown)")?,
         }
-        write!(f, ": {}", self.msg.as_deref().unwrap_or_default())
+        write!(f, ": {}", self.msg.as_deref().unwrap_or_default())?;
+        if let Some(src) = &self.source {
+            write!(f, " ({})", src)?;
+        }
+        Ok(())
     }
 }
 impl std::fmt::Debug for GitsyError {
@@ -137,8 +145,8 @@ impl std::fmt::Debug for GitsyError {
     }
 }
 impl std::error::Error for GitsyError {
-    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
-        self.source.as_deref()
+    fn source(&self) -> Option<&(dyn StdError + 'static)> {
+        self.source.as_ref().map(|c| &**c as &(dyn StdError + 'static))
     }
 }
 impl From<git2::Error> for GitsyError {