mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2024-11-12 21:39:48 +01:00
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.
This commit is contained in:
parent
75405b7b0a
commit
d47e1d65f6
1 changed files with 2 additions and 2 deletions
|
@ -88,9 +88,7 @@ EOF
|
||||||
shift
|
shift
|
||||||
|
|
||||||
# Go back to original working directory
|
# Go back to original working directory
|
||||||
# and remove extraction directory if there was an error
|
|
||||||
builtin cd -q "$pwd"
|
builtin cd -q "$pwd"
|
||||||
(( success > 0 )) && command rm -r "$extract_dir"
|
|
||||||
|
|
||||||
# If content of extract dir is a single directory, move its contents up
|
# If content of extract dir is a single directory, move its contents up
|
||||||
# Glob flags:
|
# Glob flags:
|
||||||
|
@ -102,6 +100,8 @@ EOF
|
||||||
if [[ ${#content} -eq 1 && -d "${content[1]}" ]]; then
|
if [[ ${#content} -eq 1 && -d "${content[1]}" ]]; then
|
||||||
command mv -f "${content[1]}" .
|
command mv -f "${content[1]}" .
|
||||||
command rmdir "$extract_dir"
|
command rmdir "$extract_dir"
|
||||||
|
elif [[ ${#content} -eq 0 ]]; then
|
||||||
|
command rmdir "$extract_dir"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue