Skip to content

Commit

Permalink
Cleanup of download list during trap.
Browse files Browse the repository at this point in the history
  • Loading branch information
Lasall committed Mar 14, 2018
1 parent 8d289a8 commit c26698b
Showing 1 changed file with 31 additions and 13 deletions.
44 changes: 31 additions & 13 deletions apt-fast
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,8 @@ _create_lock()
{
eval "exec $LCK_FD>\"$LCK_FILE.lock\""

trap "_remove_lock; exit" EXIT
trap "_remove_lock; exit 1;" INT TERM
trap "cleanup_aptfast; exit_cleanup_state" EXIT
trap "cleanup_aptfast; exit 1" INT TERM

flock -n $LCK_FD || { msg_already_running; exit 1; }
}
Expand All @@ -235,6 +235,35 @@ _remove_lock()
rm -f "$LCK_FILE.lock"
}

# Move download file away so missing permissions won't stop usage.
CLEANUP_STATE=0
cleanup_dllist()
{
if [ -f "$DLLIST" ]
then
if ! mv -- "$DLLIST{,.old}" 2>/dev/null
then
if ! rm -f -- "$DLLIST" 2>/dev/null
then
msg "Could not clean up download list file." "warning"
CLEANUP_STATE=1
fi
fi
fi
}

cleanup_aptfast()
{
CLEANUP_STATE=$?
cleanup_dllist
_remove_lock
}

exit_cleanup_state()
{
exit $CLEANUP_STATE
}

# decode url string
# translates %xx but must not convert '+' in spaces
urldecode()
Expand Down Expand Up @@ -613,15 +642,4 @@ else
"${_APTMGR}" "${APT_SCRIPT_WARNING[@]}" "$@"
fi
# Move download file away so missing permissions won't stop usage.
if ! mv -- "$DLLIST{,.old}" 2>/dev/null
then
if ! rm -f -- "$DLLIST" 2>/dev/null
then
msg "Could not clean up download list file." "warning"
exit 1
fi
fi
# After error or all done remove our lockfile (done with EXIT trap)

0 comments on commit c26698b

Please sign in to comment.