summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Cornellà <hello@mcornella.com>2023-04-02 16:33:54 +0200
committerMarc Cornellà <hello@mcornella.com>2023-04-02 16:33:54 +0200
commitd47e1d65f66f9bb2e7a96ba58797b33f0e91a623 (patch)
tree65492d66416d6164027cf0fceccea905c8a2317b
parent75405b7b0ae03a1fdf2fdb172d2a50cd5f570162 (diff)
downloadzsh-d47e1d65f66f9bb2e7a96ba58797b33f0e91a623.tar.gz
zsh-d47e1d65f66f9bb2e7a96ba58797b33f0e91a623.tar.bz2
zsh-d47e1d65f66f9bb2e7a96ba58797b33f0e91a623.zip
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.
-rw-r--r--plugins/extract/extract.plugin.zsh4
1 files changed, 2 insertions, 2 deletions
diff --git a/plugins/extract/extract.plugin.zsh b/plugins/extract/extract.plugin.zsh
index c416f49ce..40e67575f 100644
--- a/plugins/extract/extract.plugin.zsh
+++ b/plugins/extract/extract.plugin.zsh
@@ -88,9 +88,7 @@ EOF
shift
# Go back to original working directory
- # and remove extraction directory if there was an error
builtin cd -q "$pwd"
- (( success > 0 )) && command rm -r "$extract_dir"
# If content of extract dir is a single directory, move its contents up
# Glob flags:
@@ -102,6 +100,8 @@ EOF
if [[ ${#content} -eq 1 && -d "${content[1]}" ]]; then
command mv -f "${content[1]}" .
command rmdir "$extract_dir"
+ elif [[ ${#content} -eq 0 ]]; then
+ command rmdir "$extract_dir"
fi
done
}