[pacman-dev] [PATCH] makepkg: remove .part file after a failed download

Cedric Staniewski cedric at gmx.ca
Wed Oct 21 16:40:25 EDT 2009


Cedric Staniewski wrote:
> Xavier wrote:
>> On Wed, Oct 21, 2009 at 10:01 PM, Cedric Staniewski <cedric at gmx.ca> wrote:
>>> Ray Rashif wrote:
>>>> 2009/10/22 Xavier <shiningxc at gmail.com>
>>>>
>>>>> On Wed, Oct 21, 2009 at 7:38 PM, Cedric Staniewski <cedric at gmx.ca> wrote:
>>>>>> -       eval $dlcmd || return $?
>>>>>> +       eval $dlcmd
>>>>>> +       local ret=$?
>>>>>> +       if [ $ret -gt 0 ]; then
>>>>>> +               [ ! -s "$dlfile" ] && rm -f -- "$dlfile"
>>>>>> +               return $ret
>>>>>> +       fi
>>>>>>
>>>>> I don't understand, I cannot get it to work.
>>>>> It looks like when "eval $dlcmd" fails, nothing else is run in that
>>>>> function.
>>>>>
>>>>> I added a echo statement, but I still only see that message at the end :
>>>>> ==> ERROR: An unknown error has occurred. Exiting...
>>>>>
>>>> looks like there is no return to handle (fail but no reason given), so
>>>> makepkg traps that.
>>> That's odd. I patched makepkg from pacman 3.3.2 to test the patch, so I did not notice this.
>>> But this bug (or is it intended?) already exists in master. You can remove the "|| return $?" part from the eval line, add echos and it fails just before the second echo.
>>>
>>>
>> The issue reminded me of the following patch :
>> http://projects.archlinux.org/?p=pacman.git;a=commitdiff;h=545eac145d77c66714ec88a88056ac3827c9b240
>>
>> But it seems errexit is only enabled for build and package functions,
>> so this should not affect sources download.
> 
> Already found the responsible change. It's 'set -E' from the patch you mentioned.
> 
> There are three possible solutions I see:
> - remove set -E
> - add some code to dlcmd to handle the error code in the subshell
> - try to get rid of eval so that the code is not executed in a subshell anymore

eval is needed, so I added some code to dlcmd. This patch finally works, even with latest git. ;)
Thanks Xavier and Ray; I should really take a look in the Makefiles to find a way to only "build" makepkg.


>From e809e3182f94fd4144cdb816d0af90587bf04ea2 Mon Sep 17 00:00:00 2001
From: Cedric Staniewski <cedric at gmx.ca>
Date: Wed, 21 Oct 2009 19:13:36 +0200
-- 8< --
Subject: [PATCH] makepkg: remove empty .part files after a failed download

Signed-off-by: Cedric Staniewski <cedric at gmx.ca>
---
 scripts/makepkg.sh.in |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in
index 40367ae..78b6904 100644
--- a/scripts/makepkg.sh.in
+++ b/scripts/makepkg.sh.in
@@ -336,7 +336,12 @@ download_file() {
 		dlcmd="$dlcmd \"$url\""
 	fi
 
-	eval $dlcmd || return $?
+	local ret=0
+	eval "$dlcmd || ret=\$?"
+	if [ $ret -gt 0 ]; then
+		[ ! -s "$dlfile" ] && rm -f -- "$dlfile"
+		return $ret
+	fi
 
 	# rename the temporary download file to the final destination
 	if [ "$dlfile" != "$file" ]; then
-- 
1.6.5.1



More information about the pacman-dev mailing list