[m-rev.] for review: remove old RPMs from the BETA_WEBDIR directory.

Peter Ross pro at missioncriticalit.com
Wed Jun 30 18:38:30 AEST 2004


On Tue, Jun 29, 2004 at 11:54:16AM +1000, Fergus Henderson wrote:
> Hi Pete,
> 
> Thanks for that.  Sorry about leaving all that mess around :)
> 
> On 28-Jun-2004, Peter Ross <pro at missioncriticalit.com> wrote:
> > Note that we still don't clean up the ftp directory, but seeing that 
> > we use scp to copy the files there, I'm not sure what the best approach
> > for deleting those files is.
> 
> You can use ssh and rm, e.g. search for "FTP" in tools/test_mercury
> to see how that script does it.
> 
> > --- tools/build_rpm	16 Feb 2004 21:13:43 -0000	1.3
> > +++ tools/build_rpm	28 Jun 2004 12:08:34 -0000
> > @@ -104,10 +104,12 @@
> >  	stable)
> >  		base_version=`cat $BETA_WEBDIR/latest-stable-version`
> >  		version=$base_version
> > +		regex="[0-9]"
> >  		;;
> >  	unstable)
> >  		base_version=`cat $BETA_WEBDIR/latest-unstable-version`
> >  		version=$base_version-unstable
> > +		regex="unstable"
> >  		;;
> >  esac
> >  
> > @@ -143,9 +145,19 @@
> >     $BETA_WEBDIR/mercury-compiler-$version_with_underscores-$rel.$arch.rpm" \
> >  	|| failed 'copying RPM to web site'
> >  su mercury -c "\
> > +rm -f `find $BETA_WEBDIR -name \*$regex-$rel.$arch.rpm -and -not -name \
> > +       mercury-compiler-$version_with_underscores-$rel.$arch.rpm`" \
> > +	|| failed 'to delete old RPM'
> 
> The "-and" and "-not" arguments to "find" are not standard.
> Use "-a" and "!" instead; those are supported by the Posix standard.
> Or alternatively, it might be easier to delete the existing .rpm files
> first, and then copy the new one across; then you can just use rm without
> needing the "find" command.  That is what tools/test_mercury does for
> the .tar.gz files.
> 
> The pattern "*$regex-$rel.$arch.rpm" is overly broad, IMHO.
> Much better to use "mercury-compiler-" at the start.  You never know
> what other RPMs someone will one day put in the same directory.
> In general it is a good idea to be very careful with "rm" commands in
> scripts, especially where a complicated pattern is involved; it is easy
> to accidentally delete more than you intended to.
> 
> The argument to find's -name option is a "pattern", not a "regex",
> so the variable "regex" is misleadingly named.
> I would also put the "*" in the definitions of that variable
> rather than in the "rm" commands.  Then I'd name the variable
> "version_pattern".
> 
> Otherwise that looks good -- thanks.
> 
diff -u tools/build_rpm tools/build_rpm
--- tools/build_rpm
+++ tools/build_rpm
@@ -100,16 +100,17 @@
 # Figure out which version we are going to build
 #
 
+pat="mercury-compiler-*[0-9][0-9][0-9][0-9]_[0-9][0-9]_[0-9][0-9]"
 case $stability in
 	stable)
 		base_version=`cat $BETA_WEBDIR/latest-stable-version`
 		version=$base_version
-		regex="[0-9]"
+		pattern="$pat"
 		;;
 	unstable)
 		base_version=`cat $BETA_WEBDIR/latest-unstable-version`
 		version=$base_version-unstable
-		regex="unstable"
+		pattern="$pat"_unstable
 		;;
 esac
 
@@ -145,7 +146,7 @@
    $BETA_WEBDIR/mercury-compiler-$version_with_underscores-$rel.$arch.rpm" \
 	|| failed 'copying RPM to web site'
 su mercury -c "\
-rm -f `find $BETA_WEBDIR -name \*$regex-$rel.$arch.rpm -and -not -name \
+rm -f `find $BETA_WEBDIR -name "$pattern-$rel.$arch.rpm" -a -! -name \
        mercury-compiler-$version_with_underscores-$rel.$arch.rpm`" \
 	|| failed 'to delete old RPM'
 
@@ -154,7 +155,7 @@
    $BETA_WEBDIR/mercury-compiler-$version_with_underscores-$rel.src.rpm" \
 	|| failed "copying SRPM to web site"
 su mercury -c "\
-rm -f `find $BETA_WEBDIR -name \*$regex-$rel.src.rpm -and -not -name \
+rm -f `find $BETA_WEBDIR -name "$pattern-$rel.src.rpm" -a -! -name \
        mercury-compiler-$version_with_underscores-$rel.src.rpm`" \
 	|| failed 'to delete old source RPM'
 
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list