diff --git a/tool/apt-fast/ss-apt-fast b/tool/apt-fast/ss-apt-fast index 86731c65..72f6b9ba 100755 --- a/tool/apt-fast/ss-apt-fast +++ b/tool/apt-fast/ss-apt-fast @@ -83,6 +83,9 @@ cleanup_aptfast() if [ -n "$LISTTEMP" ] && [ -d "$LISTTEMP" ]; then rm -rf "$LISTTEMP" fi + if [ -n "$tmpdir" ] && [ -d "$tmpdir" ]; then + rm -rf "$tmpdir" + fi } exit_cleanup_state() { @@ -120,11 +123,8 @@ _create_lock() # unlock and remove the lock file _remove_lock() { - # Only unlock if lock file exists (was created by _create_lock) - if [ -f "$LCK_FILE.lock" ]; then - flock -u "$LCK_FD" 2>/dev/null - rm -f "$LCK_FILE.lock" - fi + flock -u "$LCK_FD" 2>/dev/null + rm -f "$LCK_FILE.lock" } # Search for known options and decide if root privileges are needed. @@ -134,7 +134,6 @@ for argument in "$@"; do case "$argument" in upgrade | full-upgrade | install | dist-upgrade | build-dep) option="install" - _create_lock ;; clean | autoclean) option="clean" @@ -313,6 +312,9 @@ https_proxy= [ "$TMP_http_proxy" = "$TMP_RANDOM" ] || http_proxy="$TMP_http_proxy" [ "$TMP_https_proxy" = "$TMP_RANDOM" ] || https_proxy="$TMP_https_proxy" +if [ "$option" == "install" ]; then + _create_lock +fi # Disable colors if not executed in terminal. if [ ! -t 1 ]; then @@ -456,21 +458,11 @@ get_uris(){ exit "$CLEANUP_STATE" fi prepare_auth - local tmpdir tmpdir=$(mktemp -d) || { msg "Failed to create tmp dir" "warning" msg "无法创建临时目录" "warning" exit 1 - - } - -cleanup_tmpdir() { - if [ -n "$tmpdir" ] && [ -d "$tmpdir" ]; then - rm -rf "$tmpdir" - fi -} -trap cleanup_tmpdir EXIT ## --print-uris format is: # 'fileurl' filename filesize checksum_hint:filechecksum @@ -824,9 +816,6 @@ elif [ "$option" == "download" ]; then "${_APTMGR}" "$@" fi - # Clean up temporary directory for download command - cleanup_aptfast - elif [ "$option" == "source" ]; then msg msg "Working... this may take a while." "normal" @@ -853,9 +842,6 @@ elif [ "$option" == "source" ]; then # dpkg-source -x "$(basename "$srcfile")" #done < "$DLLIST" - # Clean up temporary directory for source command - cleanup_aptfast - # Execute package manager directly if unknown options are passed. else "${_APTMGR}" "${APT_SCRIPT_WARNING[@]}" "$@"