[vhffs-dev] [1878] File::Path::rmtree now aborts if it will remove the cwd

[ Thread Index | Date Index | More vhffs.org/vhffs-dev Archives ]


Revision: 1878
Author:   gradator
Date:     2011-07-23 00:23:16 +0200 (Sat, 23 Jul 2011)
Log Message:
-----------
File::Path::rmtree now aborts if it will remove the cwd

Modified Paths:
--------------
    branches/vhffs-4.3/vhffs-robots/src/mail_deleteboxes.pl
    trunk/vhffs-robots/src/mail_deleteboxes.pl

Modified: branches/vhffs-4.3/vhffs-robots/src/mail_deleteboxes.pl
===================================================================
--- branches/vhffs-4.3/vhffs-robots/src/mail_deleteboxes.pl	2011-07-21 13:04:36 UTC (rev 1877)
+++ branches/vhffs-4.3/vhffs-robots/src/mail_deleteboxes.pl	2011-07-22 22:23:16 UTC (rev 1878)
@@ -55,16 +55,16 @@
 	if( defined $mail )  {
 
 		my $dir = $mail->get_box_dir( $b->{local_part} );
-		if( -d $dir ) {
-			if(  chdir( $dir )  )  {
-				if( defined $mailconf->{'archives_dir'}  &&  -d $mailconf->{'archives_dir'} )  {
-					my $cmd = 'tar cf '.$mailconf->{'archives_dir'}.'/'.time().'_'.$b->{local_part}.'@'.$b->{domain}.'.tar . 1> /dev/null 2> /dev/null';
-					system( $cmd );
-				}
-				File::Path::rmtree($dir);
-				# Remove the letter/ directory if empty
-				rmdir dirname($dir);
+		if( -d $dir && chdir($dir) ) {
+			if( defined $mailconf->{'archives_dir'}  &&  -d $mailconf->{'archives_dir'} )  {
+				my $cmd = 'tar cf '.$mailconf->{'archives_dir'}.'/'.time().'_'.$b->{local_part}.'@'.$b->{domain}.'.tar . 1> /dev/null 2> /dev/null';
+				system( $cmd );
 			}
+			# File::Path::rmtree abort if $dir is cwd
+			chdir('..');
+			File::Path::rmtree($dir);
+			# Remove the letter/ directory if empty
+			rmdir dirname($dir);
 		}
 		$mail->delbox( $b->{local_part} );
 	}

Modified: trunk/vhffs-robots/src/mail_deleteboxes.pl
===================================================================
--- trunk/vhffs-robots/src/mail_deleteboxes.pl	2011-07-21 13:04:36 UTC (rev 1877)
+++ trunk/vhffs-robots/src/mail_deleteboxes.pl	2011-07-22 22:23:16 UTC (rev 1878)
@@ -55,16 +55,16 @@
 	if( defined $mail )  {
 
 		my $dir = $mail->get_box_dir( $b->{local_part} );
-		if( -d $dir ) {
-			if(  chdir( $dir )  )  {
-				if( defined $mailconf->{'archives_dir'}  &&  -d $mailconf->{'archives_dir'} )  {
-					my $cmd = 'tar cf '.$mailconf->{'archives_dir'}.'/'.time().'_'.$b->{local_part}.'@'.$b->{domain}.'.tar . 1> /dev/null 2> /dev/null';
-					system( $cmd );
-				}
-				File::Path::rmtree($dir);
-				# Remove the letter/ directory if empty
-				rmdir dirname($dir);
+		if( -d $dir && chdir($dir) ) {
+			if( defined $mailconf->{'archives_dir'}  &&  -d $mailconf->{'archives_dir'} )  {
+				my $cmd = 'tar cf '.$mailconf->{'archives_dir'}.'/'.time().'_'.$b->{local_part}.'@'.$b->{domain}.'.tar . 1> /dev/null 2> /dev/null';
+				system( $cmd );
 			}
+			# File::Path::rmtree abort if $dir is cwd
+			chdir('..');
+			File::Path::rmtree($dir);
+			# Remove the letter/ directory if empty
+			rmdir dirname($dir);
 		}
 		$mail->delbox( $b->{local_part} );
 	}


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/