Skip to content

Commit

Permalink
Merge pull request #26 from adntgv/cleanup_downloaded_archive
Browse files Browse the repository at this point in the history
delete archive only if successful untar
  • Loading branch information
udhos authored Dec 6, 2020
2 parents 5480f11 + 8693c15 commit 7c17043
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ You can use the 'remove' option to undo update-golang.sh work:

$ sudo ./update-golang.sh remove

Declutter
======

You can use the '-declutter' option to prevent caching downloaded archives:

$ sudo ./update-golang.sh -declutter

Example
=======

Expand Down
10 changes: 9 additions & 1 deletion update-golang.sh
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,11 @@ has_cmd() {
tmp='' ;# will be set
save_dir=$PWD
previous_install='' ;# will be set
declutter='' ;# will be set
tar_to_remove='' ;# will be set
cleanup() {
[ -n "$tmp" ] && [ -f "$tmp" ] && msg cleanup: $tmp && rm $tmp
[ -n "$declutter" ] && [ -n "$tar_to_remove" ] && [ -f "$tar_to_remove" ] && msg cleanup: $tar_to_remove && rm $tar_to_remove
[ -n "$save_dir" ] && cd "$save_dir" || exit 2
[ -n "$previous_install" ] && msg remember to delete previous install saved as: "$previous_install"
}
Expand Down Expand Up @@ -159,6 +162,7 @@ PROFILED=$profiled
CACHE=$cache
GOPATH=$GOPATH
DEBUG=$DEBUG
EOF
}

Expand Down Expand Up @@ -261,6 +265,7 @@ untar() {
local cmd="tar -x -f $abs_filepath"
msg untar: "$cmd"
$cmd || die untar: failed: "$abs_filepath"
tar_to_remove="$abs_filepath"
}

relink() {
Expand Down Expand Up @@ -463,11 +468,14 @@ case "$1" in
remove_golang
exit 0
;;
-declutter)
declutter="true"
;;
'')
;;
*)
msg unknown option: "$1"
echo >&2 usage: "$me [-v] [remove]"
echo >&2 usage: "$me [-v] [remove] [-declutter]"
exit 1
;;
esac
Expand Down
2 changes: 1 addition & 1 deletion update-golang.sh.sha256
Original file line number Diff line number Diff line change
@@ -1 +1 @@
068538c237fee11e217f75742775b0dbef3c2059a48a10b7b566640d88f29fdb update-golang.sh
2be4b5e4c0a482364dc89f1b31921713907818abb0f40fd695a947e9361af7e8 update-golang.sh

0 comments on commit 7c17043

Please sign in to comment.