On Jul 9, 2008, at 00:29, Eric Wilhelm wrote:

# from David E. Wheeler
# on Thursday 19 June 2008 12:25:

For my install of File::Path on Perl 5.10, it
won't actually delete a directory if your current cwd is unknown. So I
  added appropriate calls to `chdir` when `Cwd::getcwd` returns
false. And now all tests pass for me.

I'm not seeing how this is required (since -d $tmp should be false if
you're in the directory) and what's with the '..'? Is that supposed to
be $cwd?

It's not because cwd returns `undef`.

  END {
    if(-d $tmp) {
-      File::Path::rmtree($tmp) or warn "cannot clean dir '$tmp'";
+      # Go back to where you came from!
+      chdir '..' or die "Couldn't chdir to $cwd";
+      File::Path::rmtree($tmp) or diag "cannot clean dir '$tmp': $@";
    }

Again. In what way is '..' correct? DistGen requires you to chdir back
yourself before calling remove().  Were there tests failing on the
original tree?

Yes, there were. Otherwise I wouldn't have done this. I changed the code to go back to the original directory where such was tracked, but in some places it was not.

sub remove {
  my $self = shift;
  croak("invalid usage -- remove()") if(@_);
+  unless (Cwd::getcwd) {
+    # How'd we get here?
+    chdir '..' or die "Couldn't chdir to ..";
+  }

I would rather resolve whatever is happening without chdir('..') -- if
only to avoid writing an enormous comment to explain why something
which looks so wrong exists.

I can give you access to my box to play with it yourself, if you don't have one handy.

Best,

David

Reply via email to