]> sipb.mit.edu Git - ikiwiki.git/blobdiff - IkiWiki/Plugin/cvs.pm
Fix longstanding bug (chdir to nonexistent dirs).
[ikiwiki.git] / IkiWiki / Plugin / cvs.pm
index 759ea1c23b3d76672155d66b559c3cda6ed0c124..bccab3159b494cfc7f0757ec224f9f8be8ed8409 100644 (file)
@@ -502,7 +502,16 @@ sub cvs_runcvs(@) {
        my @cmd = @_;
        unshift @cmd, 'cvs', '-Q';
 
-       local $CWD = $config{srcdir};
+       # CVS can't operate outside a srcdir, so we're always setting $CWD.
+       # "local $CWD" restores the previous value when we go out of scope.
+       # Usually that's correct. But if we're removing the last file from
+       # a directory, the post-commit hook will exec in a working directory
+       # that's about to not exist (CVS will prune it).
+       #
+       # chdir() manually here, so we can selectively not chdir() back.
+
+       my $oldcwd = $CWD;
+       chdir($config{srcdir});
 
        eval q{
                use IPC::Open3;
@@ -530,6 +539,8 @@ sub cvs_runcvs(@) {
        print STDOUT $cvsout;
        print STDERR $cvserr;
 
+       chdir($oldcwd) if -d $oldcwd;
+
        return ($ret == 0) ? 1 : 0;
 }