Mail Archives: cygwin/2002/07/24/11:35:32
------=_NextPart_000_0013_01C2332F.49C7B720
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
First, thanks to Michael for a _very_ useful tool. I've made a few tweaks to it
over time, and I'm now going to submit a patch or two.
Here is one implementing this feature:
-[no]AFile
Move obsolete files to a directory 'Attic' in the root of the local package
directory, maintaining their position in the directory structure (i.e.
release/foo/foo-1.0-1.tar.bz2 -> Attic/release/foo/foo-1.0-1.tar.bz2).
In this patch, I hardcoded 'Attic' into the ignore list. I'm not sure whether
that is the best thing to do or not. Maybe it should only be auto-ignored
if -AFile is set?
Anyway, here's the patch - comments welcomed.
Max.
------=_NextPart_000_0013_01C2332F.49C7B720
Content-Type: text/plain;
name="clean_setup_1.0402+attic.patch"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
filename="clean_setup_1.0402+attic.patch"
--- clean_setup_1.0402.pl 2002-05-24 21:21:04.000000000 +0100=0A=
+++ clean_setup_1.0402+attic.pl 2002-07-24 16:23:58.000000000 +0100=0A=
@@ -49,6 +49,12 @@=0A=
=0A=
Delete obsolete files.=0A=
=0A=
+=3Ditem -[no]AFile=0A=
+=0A=
+Move obsolete files to a directory 'Attic' in the root of the local=0A=
+package directory, maintaining their position in the directory structure=0A=
+(i.e. release/foo/foo-1.0-1.tar.bz2 -> =
Attic/release/foo/foo-1.0-1.tar.bz2).=0A=
+=0A=
=3Ditem -[no]DSetup=0A=
=0A=
Delete obsolete setup.ini files.=0A=
@@ -166,6 +172,7 @@=0A=
# Initialize options=0A=
my $bDDir =3D 0;=0A=
my $bDFile =3D 0;=0A=
+my $bAFile =3D 0;=0A=
my $bDSetup =3D 0;=0A=
my $bCSetup =3D 0;=0A=
my $bMFile =3D 0;=0A=
@@ -176,7 +183,7 @@=0A=
my $bSource =3D 0;=0A=
my $sMissList =3D "";=0A=
my @sHide =3D ();=0A=
-my @sIgnore =3D ();=0A=
+my @sIgnore =3D ( 'Attic' );=0A=
my $sDir0 =3D File::Spec -> rel2abs( "." );=0A=
=0A=
# Get default setup local files directory from /etc/setup/last-cache=0A=
@@ -208,6 +215,7 @@=0A=
Opt: ($VERSION)=0A=
-[no]DDir =3D [Don't] Delete directories ($bDDir)=0A=
-[no]DFile =3D [Don't] Delete files not in setup.ini ($bDFile)=0A=
+ -[no]AFile =3D [Don't] Move files not in setup.ini to the Attic =
($bAFile)=0A=
-[no]DSetup =3D [Don't] Delete obsolete setup.ini files ($bDSetup)=0A=
-[no]CSetup =3D [Don't] Copy latest setup.ini file to base =
directory ($bCSetup)=0A=
-[no]MFile =3D [Don't] Move files to base directory tree ($bMFile)=0A=
@@ -228,6 +236,8 @@=0A=
=0A=
my $nRet =3D 'help' eq $sOpt ? 0 : 0 + $sVal;=0A=
select STDERR if $nRet;=0A=
+# This is to separate a message from the beginning of the usage=0A=
+ if (@sMsg) { push @sMsg, ''; }=0A=
foreach ( @sMsg, $sHelpText ) { s/\s+$//; print "$_\n"; }=0A=
exit $nRet;=0A=
}=0A=
@@ -237,6 +247,7 @@=0A=
GetOptions(=0A=
'DDir|DD!' =3D> \$bDDir,=0A=
'DFile|DF!' =3D> \$bDFile,=0A=
+ 'AFile|AF!' =3D> \$bAFile,=0A=
'DSetup|DS!' =3D> \$bDSetup,=0A=
'CSetup|CS!' =3D> \$bCSetup,=0A=
'MFile|MF!' =3D> \$bMFile,=0A=
@@ -254,12 +265,16 @@=0A=
=0A=
# Provide default values for unset options and parameters=0A=
=0A=
+# Complain about invalid parameter combinations=0A=
+usage( 'die', 1, "Can't both delete and move files not in setup.ini!\n" =
) if ($bDFile and $bAFile);=0A=
+=0A=
# Report arguments=0A=
$sDir0 =3D File::Spec -> rel2abs( "." );=0A=
$sDir0 =3D~ s,\\,/,g;=0A=
my $sOpt =3D '';=0A=
$sOpt .=3D "\nDeleting empty directores" if $bDDir;=0A=
$sOpt .=3D "\nDeleting files not in setup.ini" if $bDFile;=0A=
+$sOpt .=3D "\nMoving files not in setup.ini to the Attic" if $bAFile;=0A=
$sOpt .=3D "\nDeleting obsolete setup.ini files" if $bDSetup;=0A=
$sOpt .=3D "\nCopying latest setup.ini to base directory" if $bCSetup;=0A=
$sOpt .=3D "\nMoving archives to base directory tree" if $bMFile;=0A=
@@ -382,7 +397,7 @@=0A=
}=0A=
=0A=
# Check found files against those listed in latest setup.ini=0A=
-my ( @sDir, $sDir, $sFile, @sDup, %sMove, @sRemove, @sWrongSize );=0A=
+my ( @sDir, $sDir, $sFile, @sDup, %sMove, @sNotInSetupIni, @sWrongSize =
);=0A=
my %aInstall =3D ( %{$aSetup{$sNewest}[1]} );=0A=
my %aSource =3D ( %{$aSetup{$sNewest}[2]} );=0A=
foreach $sName ( sort keys %sTarBall ) {=0A=
@@ -419,7 +434,7 @@=0A=
}=0A=
else {=0A=
# File not in setup.ini=0A=
- push @sRemove, $sFile;=0A=
+ push @sNotInSetupIni, $sFile;=0A=
}=0A=
}=0A=
=0A=
@@ -482,13 +497,12 @@=0A=
}=0A=
=0A=
# Remove files not listed in setup.ini=0A=
-if ( @sRemove ) {=0A=
- print $bDFile ? "\n" : "\nNot ", "Removing files not in setup.ini\n";=0A=
- foreach $sFile ( @sRemove ) {=0A=
+if ( @sNotInSetupIni ) {=0A=
+ print "\nFiles not in setup.ini: ", $bDFile ? "Removing\n" : $bAFile =
? "Moving to the Attic\n" : "No Action\n";=0A=
+ foreach $sFile ( @sNotInSetupIni ) {=0A=
print sUnPercent( " $sFile\n" );=0A=
- if ( $bDFile ) {=0A=
- unlink( $sFile ) or print " *** Can't remove, $!\n";=0A=
- }=0A=
+ unlink( $sFile ) or print " *** Can't remove, $!\n" if =
$bDFile;=0A=
+ to_attic( $sFile ) or print " *** Can't move to Attic, $!\n" =
if $bAFile;=0A=
}=0A=
}=0A=
=0A=
@@ -533,3 +547,9 @@=0A=
s/\%([0-9a-f]{2})/chr(hex($1))/gie;=0A=
return $_;=0A=
}=0A=
+=0A=
+# Move file to Attic=0A=
+sub to_attic {=0A=
+ mkpath( dirname(File::Spec->catdir('Attic', $_[0])) );=0A=
+ return rename( $_[0], File::Spec->catdir('Attic', $_[0]) );=0A=
+}=0A=
------=_NextPart_000_0013_01C2332F.49C7B720
Content-Type: text/plain; charset=us-ascii
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Bug reporting: http://cygwin.com/bugs.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
------=_NextPart_000_0013_01C2332F.49C7B720--
- Raw text -