fix(extract): safely remove extract directory
The previous code would remove the extract directory if the command failed.
This could be bad because we're not checking if the extract directory
already existed (since we're using `mkdir -p`), so it could be possible
that the extract operation failed, and we'd be removing a directory that
already existed and had files in it.
This change only removes the directory if there are no files in it, regardless
of whether the extract operation was successful or not. This is much safer.
Diff
1diff --git a/plugins/extract/extract.plugin.zsh b/plugins/extract/extract.plugin.zsh
2index c416f49ce3a6c293c2b1a6544b78833a9d73f6dc..40e67575f813ea1a3561bb4e1fcc087504b5596f 100644
3--- a/plugins/extract/extract.plugin.zsh
4+++ b/plugins/extract/extract.plugin.zsh
5@@ -88,9 +88,7 @@ EOF
6 shift
7 8 # Go back to original working directory
9- # and remove extraction directory if there was an error
10 builtin cd -q "$pwd"
11- (( success > 0 )) && command rm -r "$extract_dir"
1213 # If content of extract dir is a single directory, move its contents up
14 # Glob flags:
15@@ -102,6 +100,8 @@ EOF
16 if [[ ${#content} -eq 1 && -d "${content[1]}" ]]; then
17 command mv -f "${content[1]}" .
18 command rmdir "$extract_dir"
19+ elif [[ ${#content} -eq 0 ]]; then
20+ command rmdir "$extract_dir"
21 fi
22 done
23 }