# Bug in fileutils.rb

**URL:** <https://rubytalk.org/t/bug-in-fileutils-rb/10491>\
**Category:** ruby-talk\
**Created:** [10 March 2004 09:04 UTC](https://rubytalk.org/t/bug-in-fileutils-rb/10491 "2004-03-10T09:04:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Christian\_Loew](https://avatars.discourse-cdn.com/v4/letter/c/54ee81/32.png) [@Christian\_Loew](https://rubytalk.org/u/Christian_Loew)\
**Post date:** [10 March 2004 09:04 UTC](https://rubytalk.org/t/bug-in-fileutils-rb/10491/1 "2004-03-10T09:04:38Z")

</div>

it seems that i found a bug in fileutils with symbolic.links

my System:  
debian/woody with ruby-backport  
ruby 1.8.1 (2004-02-03) [i386-linux]

i made a symlink on a directory like the following example:

loew@ssflx01\_v4:/tmp/ruby$ ls -laR  
.:  
total 16  
drwxr-xr-x 4 loew loew 4096 Mar 10 09:48 .  
drwxrwxrwt 4 root root 4096 Mar 10 09:48 …  
drwxr-xr-x 2 loew loew 4096 Mar 10 09:48 tst  
drwxr-xr-x 2 loew loew 4096 Mar 10 09:48 tst2

./tst:  
total 8  
drwxr-xr-x 2 loew loew 4096 Mar 10 09:48 .  
drwxr-xr-x 4 loew loew 4096 Mar 10 09:48 …  
lrwxrwxrwx 1 loew loew 7 Mar 10 09:48 tst2 -\> …/tst2

./tst2:  
total 8  
drwxr-xr-x 2 loew loew 4096 Mar 10 09:48 .  
drwxr-xr-x 4 loew loew 4096 Mar 10 09:48 …

loew@ssflx01\_v4:/tmp/ruby$ ruby1.8 -e ‘require “fileutils”; FileUtils.rm\_r("/tmp/ruby/tst")’  
/usr/lib/ruby/1.8/fileutils.rb:591:in rmdir’: Not a directory -  
/tmp/ruby/tst/tst2 (Errno::ENOTDIR)  
from /usr/lib/ruby/1.8/fileutils.rb:591:in remove\_dir’  
from /usr/lib/ruby/1.8/fileutils.rb:585:in remove\_dir’  
from /usr/lib/ruby/1.8/fileutils.rb:581:in foreach’  
from /usr/lib/ruby/1.8/fileutils.rb:581:in remove\_dir’  
from /usr/lib/ruby/1.8/fileutils.rb:542:in rm\_r’  
from /usr/lib/ruby/1.8/fileutils.rb:534:in each’  
from /usr/lib/ruby/1.8/fileutils.rb:534:in rm\_r’  
from -e:1

my patch:  
ssflx01\_v4:/usr/lib/ruby/1.8# diff -a -c fileutils.rb.old fileutils.rb  
\*\*\* fileutils.rb.old Wed Mar 10 09:42:34 2004  
— fileutils.rb Wed Mar 10 09:56:03 2004

> **···**
>
> * * *
> 
> \*\*\* 581,587 \*\*\*\*  
> Dir.foreach(dir) do |file|  
> next if /\A…?\z/ === file  
> path = “#{dir}/#{file}”  
> ! if File.directory?(path)  
> remove\_dir path, force  
> else  
> remove\_file path, force  
> — 581,589 ----  
> Dir.foreach(dir) do |file|  
> next if /\A…?\z/ === file  
> path = “#{dir}/#{file}”  
> ! if File.symlink?(path)  
> ! remove\_file path, force  
> ! elsif File.directory?(path)  
> remove\_dir path, force  
> else  
> remove\_file path, force
> 
> regards,
> 
> Löw Christian

---

<div class="post-metadata">

**Author:** ![Minero\_Aoki](https://avatars.discourse-cdn.com/v4/letter/m/71c47a/32.png) [@Minero\_Aoki](https://rubytalk.org/u/Minero_Aoki)\
**Post date:** [10 March 2004 13:29 UTC](https://rubytalk.org/t/bug-in-fileutils-rb/10491/2 "2004-03-10T13:29:21Z")

</div>

Hi,

In mail “bug in fileutils.rb”

> **···**
>
> Christian Loew [chris@chello.at](mailto:chris@chello.at) wrote:
> 
> > it seems that i found a bug in fileutils with symbolic.links
> 
> > loew@ssflx01\_v4:/tmp/ruby$ ruby1.8 -e ‘require “fileutils”; FileUtils.rm\_r(“/tmp/ruby/tst”)’  
> > /usr/lib/ruby/1.8/fileutils.rb:591:in rmdir’: Not a directory -
> 
> Thank you very much.  
> I have commited your patch now.
> 
> Best Regards,  
> Minero Aoki
