[Bps-public-commit] r14384 - in Shipwright/trunk: lib/Shipwright/Source

sunnavy at bestpractical.com sunnavy at bestpractical.com
Tue Jul 22 12:42:12 EDT 2008


Author: sunnavy
Date: Tue Jul 22 12:42:11 2008
New Revision: 14384

Modified:
   Shipwright/trunk/   (props changed)
   Shipwright/trunk/lib/Shipwright/Source/Compressed.pm
   Shipwright/trunk/lib/Shipwright/Source/Directory.pm

Log:
 r14839 at sunnavys-mb:  sunnavy | 2008-07-23 00:41:57 +0800
 refactor a bit, fixing  tricky bugs


Modified: Shipwright/trunk/lib/Shipwright/Source/Compressed.pm
==============================================================================
--- Shipwright/trunk/lib/Shipwright/Source/Compressed.pm	(original)
+++ Shipwright/trunk/lib/Shipwright/Source/Compressed.pm	Tue Jul 22 12:42:11 2008
@@ -23,9 +23,12 @@
     $self->_update_url( $self->name, 'file:' . $self->source )
       unless $self->{_no_update_url};
 
+    my $newer = $self->_cmd; # if we really get something new
+
     my $ret = $self->SUPER::run(@_);
+    # follow only if --follow and we really added new stuff.
     $self->_follow( File::Spec->catfile( $self->directory, $self->name ) )
-      if $self->follow;
+      if $self->follow && $newer;
     return File::Spec->catfile( $self->directory, $self->name );
 }
 
@@ -67,34 +70,25 @@
         croak "I've no idea what the cmd is";
     }
 
+
+    my ( $from, $to );
+    $from = File::Spec->catfile( $self->directory, $self->path );
+    $to = File::Spec->catfile( $self->directory, $self->name );
+
+# if it already exists, assuming we have processed it already, don't do it
+# again
+    return if -e $to; 
+
     my @cmds;
     push @cmds, [ 'tar', $arg, $self->source, '-C', $self->directory ];
-
-    if ( $self->name && $self->name ne $self->path ) {
-        if ( -e File::Spec->catfile( $self->directory, $self->name ) ) {
-            push @cmds,
-              [
-                'rm', '-rf',
-                File::Spec->catfile( $self->directory, $self->path )
-              ],
-
-        }
-        else {
-            push @cmds,
-              [
-                'mv',
-                File::Spec->catfile( $self->directory, $self->path ),
-                File::Spec->catfile( $self->directory, $self->name )
-              ];
-        }
-    }
-    else {
-        my $from = File::Spec->catfile( $self->directory, $self->path );
-        my $to =
-          File::Spec->catfile( $self->directory,
-            $self->just_name( $self->path ) );
-        push @cmds, [ 'mv', $from, $to ]
-          unless $from eq $to;
+    
+    if ( $from ne $to ) {
+        push @cmds,
+          [
+            'mv',
+            $from,
+            $to,
+          ];
     }
 
     return @cmds;

Modified: Shipwright/trunk/lib/Shipwright/Source/Directory.pm
==============================================================================
--- Shipwright/trunk/lib/Shipwright/Source/Directory.pm	(original)
+++ Shipwright/trunk/lib/Shipwright/Source/Directory.pm	Tue Jul 22 12:42:11 2008
@@ -35,12 +35,15 @@
     $self->_update_url( $self->name || $self->just_name( $self->path ),
         'directory:' . $self->source ) unless $self->{_no_update_url};
 
+    my $newer = $self->_cmd; # if we really get something new
+
     $self->SUPER::run(@_);
+    # follow only if --follow and we really added new stuff.
     $self->_follow(
         File::Spec->catfile(
             $self->directory, $self->name || $self->just_name( $self->path )
         )
-    ) if $self->follow;
+    ) if $self->follow && $newer;
     return File::Spec->catfile( $self->directory,
         $self->name || $self->just_name( $self->path ) );
 }
@@ -58,12 +61,12 @@
 
 sub _cmd {
     my $self = shift;
-    return [
-        'cp', '-r',
-        $self->source,
-        File::Spec->catfile( $self->directory,
-            $self->name || $self->just_name( $self->path ) )
-    ];
+    my $to =
+      File::Spec->catfile( $self->directory,
+        $self->name || $self->just_name( $self->path ) );
+    return if -e $to;
+
+    return [ 'cp', '-r', $self->source, $to ];
 }
 
 1;



More information about the Bps-public-commit mailing list