# Possible bug in FileUtils::fu\_mkdir (Errno::EEXIST)

**URL:** <https://www.ruby-forum.com/t/possible-bug-in-fileutils-fu-mkdir-errno-eexist/191368>\
**Category:** Ruby\
**Created:** [July 10, 2010, 5:34pm UTC](https://www.ruby-forum.com/t/possible-bug-in-fileutils-fu-mkdir-errno-eexist/191368 "2010-07-10T17:34:46Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [July 10, 2010, 5:34pm UTC](https://www.ruby-forum.com/t/possible-bug-in-fileutils-fu-mkdir-errno-eexist/191368/1 "2010-07-10T17:34:46Z")

</div>

Hello,

We are getting some reports in RubyInstaller project of weird gem  
installation issues.

[http://groups.google.com/group/rubyinstaller/browse\_thread/thread/df7b7c217ad7d882](http://groups.google.com/group/rubyinstaller/browse_thread/thread/df7b7c217ad7d882)

The bug output is the following:

ERROR: While executing gem … (Errno::EEXIST)  
File exists - C:

I’ve created a simplified test case:

require ‘fileutils’  
system(“rd C:\Foo /S/Q”)  
FileUtils.mkdir\_p ‘C:/Foo/Bar/Baz’, :verbose =\> true

And the following is the output:

C:\Users\Luis\>ruby -v t.rb  
ruby 1.8.7 (2010-06-23 patchlevel 299) [i386-mingw32]  
mkdir -p C:/Foo/Bar/Baz  
C:/Users/Luis/Tools/Ruby/ruby-1.8.7-p299-i386-mingw32/lib/ruby/1.8/fileutils.rb:244:in  
`mkdir': File exists - C: (Errno::EEXIST) from C:/Users/Luis/Tools/Ruby/ruby-1.8.7-p299-i386-mingw32/lib/ruby/1.8/fileutils.rb:244:in `fu\_mkdir’  
from  
C:/Users/Luis/Tools/Ruby/ruby-1.8.7-p299-i386-mingw32/lib/ruby/1.8/fileutils.rb:217:in  
`mkdir_p' from C:/Users/Luis/Tools/Ruby/ruby-1.8.7-p299-i386-mingw32/lib/ruby/1.8/fileutils.rb:215:in `reverse\_each’  
from  
C:/Users/Luis/Tools/Ruby/ruby-1.8.7-p299-i386-mingw32/lib/ruby/1.8/fileutils.rb:215:in  
`mkdir_p' from C:/Users/Luis/Tools/Ruby/ruby-1.8.7-p299-i386-mingw32/lib/ruby/1.8/fileutils.rb:201:in `each’  
from  
C:/Users/Luis/Tools/Ruby/ruby-1.8.7-p299-i386-mingw32/lib/ruby/1.8/fileutils.rb:201:in  
`mkdir\_p’  
from t.rb:3

This happens with 1.8.6, 1.8.7 and 1.9.1 prior patchlevel 429. This do  
not show up with 1.9.1, nor with JRuby or IronRuby:

> <https://gist.github.com/luislavena/047915f46a88eb11dfcb>

Checking the code of FileUtils, specially fu\_mkdir:

def fu\_mkdir(path, mode) #:nodoc:  
path = path.sub(%r\</\z\>, ‘’)  
if mode  
Dir.mkdir path, mode  
File.chmod mode, path  
else  
Dir.mkdir path  
end  
end

Seems that no matter if path exists and is a directory, it tries to  
create it.

It fails on Windows when tries to create “C:”, since it never tries to  
test for File.directory?(“C:”)

Adding the following line before mode solves the problem:

```
return if File.directory?(path)

```

But the weird part of this is that the problem didn’t existed before,  
just after E-Text Editor installation (which install cygwin)

I’ve removed all traces of both programs, registry and environment  
variables but the issue I’ve presented above is not going away.

The question is more related to the rescue SystemCallError and the  
“next unless File.directory?(path)”

fu\_mkdir path call modifies path removing trailing slashes, so:

File.directory?(‘C:/’) # =\> false

becomes:

File.directory?(‘C:’) # =\> true

The only problem is that for some reason, path contains the previous  
value, not the altered and correct one.

This is a bug? I doubt since it only appeared after the issue  
mentioned above, but still wanted to check prior reporting to  
Ruby-Core.

Thank you for your attention.
