sup rev 25

Better clean up on upload errors
author Christophe Lincoln <pankso@slitaz.org>
date Mon Feb 27 13:24:42 2017 +0100 (2017-02-27)
parents 690b94e42aa8
children 32f5aaba49d1
files server/sup/sup.cgi
line diff
     1.1 --- a/server/sup/sup.cgi	Mon Feb 27 12:31:36 2017 +0100
     1.2 +++ b/server/sup/sup.cgi	Mon Feb 27 13:24:42 2017 +0100
     1.3 @@ -115,16 +115,27 @@
     1.4  		suplog="$scn/cache/log/sup.log"
     1.5  		error=0
     1.6  		
     1.7 +		# clean_error "Message"
     1.8 +		clean_error() {
     1.9 +			echo "<span class='error'>ERROR: ${1}</span>"
    1.10 +			[ -d "$cache" ] && rm -rf ${cache} 
    1.11 +			[ -d "$(dirname $tmpfile)" ] && rm -rf $(dirname $tmpfile)
    1.12 +		}
    1.13 +		
    1.14  		# Use COOKIE to make sure user is logged in SCN/SUP Hub
    1.15  		user="$(echo $(COOKIE auth) | cut -d ':' -f 1)"
    1.16  		if [ "$(COOKIE auth)" ] && [ "$user" != "$(GET user)" ]; then
    1.17 -			echo "<pre>ERROR: user auth cookie</pre>" && exit 1
    1.18 +			clean_error "user auth cookie" && exit 1
    1.19  		fi
    1.20  		
    1.21  		#if [ ! -f "$pkgsdb" ]; then
    1.22  			#echo "<pre>ERROR: missing $pkgsdb</pre>" && exit 1
    1.23  		#fi
    1.24  		
    1.25 +		if [ "$supfile" != "${supfile%.sup}.sip" ]; then
    1.26 +			clean_error "not a .sup package" && exit 1
    1.27 +		fi
    1.28 +		
    1.29  		cat << EOT
    1.30  <!DOCTYPE html>
    1.31  <html lang="en">
    1.32 @@ -140,10 +151,15 @@
    1.33  SUP Hub user   : <a href="${host}?user=$user">$user</a>
    1.34  Package file   : ${supfile}
    1.35  EOT
    1.36 +
    1.37 +		# Is it a .sup file
    1.38 +		
    1.39 +		
    1.40 +		
    1.41  		mkdir -p ${cache}
    1.42  		if ! mv -f ${tmpfile} ${cache}/${supfile}; then
    1.43 -			echo "<span class='error'>ERROR moving: ${tmpfile} to ${supfile}</span></pre>"
    1.44 -			rm -rf ${cache} $(dirname $tmpfile) && exit 1
    1.45 +			clean_error "moving: ${tmpfile} to ${supfile}" 
    1.46 +			echo "</pre>" && exit 1
    1.47  		fi
    1.48  		
    1.49  		# Show MD5sum
    1.50 @@ -153,12 +169,16 @@
    1.51  		# sure SCN user name match package MAINTAINER.
    1.52  		gettext "Extracting receip..."
    1.53  		cd ${cache}
    1.54 -		cpio -i receip --quiet < ${supfile}
    1.55 +		if ! cpio -i receip --quiet < ${supfile}; then
    1.56 +			echo ""
    1.57 +			clean_error "Can't extract receip"
    1.58 +			echo "</pre>" && exit 1
    1.59 +		fi
    1.60  		status
    1.61  		
    1.62  		if ! . receip; then
    1.63 -			echo "<span class='error'>ERROR: Can't source receip</span></pre>"
    1.64 -			rm -rf ${cache} $(dirname $tmpfile) && exit 1
    1.65 +			clean_error "Can't source receip"
    1.66 +			echo "</pre>" && exit 1
    1.67  		fi
    1.68  		echo "build_date: $build_date"
    1.69  		
    1.70 @@ -255,7 +275,8 @@
    1.71  		fi
    1.72  		cat << EOT
    1.73  <p>
    1.74 -	SliTaz User Packages services: Beta :-)
    1.75 +	SliTaz User Packages services: Beta :-) -
    1.76 +	<a href="http://scn.slitaz.org/index.cgi?d=en/sup">Documentation</a>
    1.77  </p>
    1.78  
    1.79  <pre>