Re: chdir(..) dance for 5.10 on osx?

[email protected] (Eric Wilhelm)
Newsgroups perl.module.build
Message-ID <[email protected]>
# 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?

   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?

 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.

--Eric
-- 
Entia non sunt multiplicanda praeter necessitatem.
--Occam's Razor
---------------------------------------------------
    http://scratchcomputing.com
---------------------------------------------------
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.