I think I have found a bug in Dir.chdir.

That method has special logic to issue a warning if a new "chdir" call
is done while another "chdir" call with a block is still "active".
This is managed with a counter "chdir_blocking" in the C source in
"dir.c".  The problem is that this counter is not maintained correctly
if the first "chdir" fails. An example demonstrates the problem:

  begin
    Dir.chdir("non-existing") do
      # ...
    end
  rescue
    # ...
  end
  Dir.chdir "existing"    # gives the warning below:
  # test-chdir.rb:8: warning: conflicting chdir during another chdir block

That warning should not be issued in this situation since we have
already exited the first "chdir" call when we are executing the
second "chdir" on line 8.

I think my patch given below solves the problem.

/Johan Holmberg


Index: dir.c
===================================================================
RCS file: /src/ruby/dir.c,v
retrieving revision 1.125
diff -u -r1.125 dir.c
--- dir.c	19 Aug 2004 07:33:15 -0000	1.125
+++ dir.c	21 Aug 2004 20:44:44 -0000
@@ -767,10 +767,10 @@

     if (rb_block_given_p()) {
 	char *cwd = my_getcwd();
+	dir_chdir(dist);
 	chdir_blocking++;
 	if (chdir_thread == Qnil)
 	    chdir_thread = rb_thread_current();
-	dir_chdir(dist);
 	return rb_ensure(rb_yield, path, chdir_restore, (VALUE)cwd);
     }
     dir_chdir(dist);