From 7f5ff0faf1c95705e451bfa7da522eb2f75bc2a0 Mon Sep 17 00:00:00 2001 From: Spyros Roum Date: Tue, 2 Nov 2021 13:34:38 +0200 Subject: [PATCH] Fix archives panicking when asked to overwrite file --- src/archive/tar.rs | 4 ++-- src/archive/zip.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/archive/tar.rs b/src/archive/tar.rs index a778728..c71cdbb 100644 --- a/src/archive/tar.rs +++ b/src/archive/tar.rs @@ -35,10 +35,10 @@ pub fn unpack_archive( } if file_path.is_dir() { - // We can't just use `fs::File::create(&file_path)` because it would return io::ErrorKind::IsADirectory // ToDo: Maybe we should emphasise that `file_path` is a directory and everything inside it will be gone? fs::remove_dir_all(&file_path)?; - fs::File::create(&file_path)?; + } else if file_path.is_file() { + fs::remove_file(&file_path)?; } file.unpack_in(output_folder)?; diff --git a/src/archive/zip.rs b/src/archive/zip.rs index 83de647..9085129 100644 --- a/src/archive/zip.rs +++ b/src/archive/zip.rs @@ -42,10 +42,10 @@ where } if file_path.is_dir() { - // We can't just use `fs::File::create(&file_path)` because it would return io::ErrorKind::IsADirectory // ToDo: Maybe we should emphasise that `file_path` is a directory and everything inside it will be gone? fs::remove_dir_all(&file_path)?; - fs::File::create(&file_path)?; + } else if file_path.is_file() { + fs::remove_file(&file_path)?; } check_for_comments(&file);