From a87b89073e1dd251d49508559f6965f9c7f4adec Mon Sep 17 00:00:00 2001 From: Nbiba Bedis Date: Tue, 16 Nov 2021 09:32:01 +0100 Subject: [PATCH] Document unwrap safety --- src/commands.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/commands.rs b/src/commands.rs index 17f6f7b..e23f02c 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -538,9 +538,10 @@ fn smart_unpack( let root_contains_only_one_element = fs::read_dir(&temp_dir_path)?.count() == 1; if root_contains_only_one_element { // Only one file in the root directory, so we can just move it to the output directory - let file = fs::read_dir(&temp_dir_path)?.next().unwrap().unwrap(); + let file = fs::read_dir(&temp_dir_path)?.next().expect("item exists")?; let file_path = file.path(); - let file_name = file_path.file_name().unwrap().to_str().unwrap(); + let file_name = + file_path.file_name().expect("Should be safe because paths in archives should not end with '..'"); let correct_path = output_dir.join(file_name); // One case to handle tough is we need to check if a file with the same name already exists if !utils::clear_path(&correct_path, question_policy)? {