From 4d1a8a95774dbb7ea73097bf481d4e1e97e8c805 Mon Sep 17 00:00:00 2001 From: Martin Hoffmann Date: Thu, 13 Jan 2022 11:10:10 +0100 Subject: [PATCH] =?UTF-8?q?Cope=20with=20stray=20files=20in=20the=20rsync?= =?UTF-8?q?=20collector=E2=80=99s=20directory.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/collector/rsync.rs | 4 ++-- src/utils/fatal.rs | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/collector/rsync.rs b/src/collector/rsync.rs index fa2413f..110b522 100644 --- a/src/collector/rsync.rs +++ b/src/collector/rsync.rs @@ -364,7 +364,7 @@ impl<'a> Run<'a> { }; if !keep { - fatal::remove_dir_all(entry.path())?; + fatal::remove_all(entry.path())?; } } @@ -395,7 +395,7 @@ impl<'a> Run<'a> { }; if !keep { - fatal::remove_dir_all(entry.path())?; + fatal::remove_all(entry.path())?; } else { keep_host = true; diff --git a/src/utils/fatal.rs b/src/utils/fatal.rs index b19500c..b14ee8d 100644 --- a/src/utils/fatal.rs +++ b/src/utils/fatal.rs @@ -214,6 +214,19 @@ pub fn remove_file(path: &Path) -> Result<(), Failed> { } +//------------ remove_all ---------------------------------------------------- + +/// Removes a file or a directory tree. +pub fn remove_all(path: &Path) -> Result<(), Failed> { + if path.is_dir() { + remove_dir_all(path) + } + else { + remove_file(path) + } +} + + //------------ rename -------------------------------------------------------- /// Renames a file or directory.