Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

seed _exists hash with old files & use abs path, so dryrun mode can m…

…ore accurately simulate
  • Loading branch information...
commit a029e00c578a913af31f0d193ae9ea86a61839ef 1 parent 5949a58
Steven Haryanto authored July 05, 2010

Showing 1 changed file with 20 additions and 15 deletions. Show diff stats Hide diff stats

  1. 35  lib/App/perlmv.pm
35  lib/App/perlmv.pm
@@ -355,22 +355,11 @@ sub process_item {
355 355
     $self->run_code();
356 356
     my $new = $_;
357 357
 
358  
-    return if abs_path($old) eq abs_path($new);
  358
+    my $aold = abs_path($old);
  359
+    my $anew = abs_path($new);
  360
+    $self->{_exists}{$aold}++ if (-e $aold);
  361
+    return if $aold eq $anew;
359 362
 
360  
-    my $cwd = getcwd();
361  
-    my $orig_new = $new;
362  
-    unless ($self->{'overwrite'}) {
363  
-        my $i = 1;
364  
-        while (1) {
365  
-            if ((-e $new) || exists $self->{_exists}{"$cwd/$new"}) {
366  
-                $new = "$orig_new.$i";
367  
-                $i++;
368  
-            } else {
369  
-                last;
370  
-            }
371  
-        }
372  
-        $self->{_exists}{"$cwd/$new"}++;
373  
-    }
374 363
     my $action;
375 364
     if (!defined($self->{mode}) || $self->{mode} =~ /^(rename|r)$/) {
376 365
         $action = "rename";
@@ -384,6 +373,22 @@ sub process_item {
384 373
         die "Unknown mode $self->{mode}, please use one of: ".
385 374
             "rename (r), copy (c), symlink (s), or link (l).";
386 375
     }
  376
+
  377
+    my $orig_new = $new;
  378
+    unless ($self->{'overwrite'}) {
  379
+        my $i = 1;
  380
+        while (1) {
  381
+            if ((-e $new) || exists $self->{_exists}{$anew}) {
  382
+                $new = "$orig_new.$i";
  383
+                $anew = abs_path($new);
  384
+                $i++;
  385
+            } else {
  386
+                last;
  387
+            }
  388
+        }
  389
+    }
  390
+    $self->{_exists}{$anew}++;
  391
+    delete $self->{_exists}{$aold} if $action eq 'rename';
387 392
     print "DRYRUN: " if $self->{dry_run};
388 393
     print "$action `$old` -> `$new`\n" if $self->{verbose};
389 394
     unless ($self->{dry_run}) {

0 notes on commit a029e00

Please sign in to comment.
Something went wrong with that request. Please try again.