# Bug in FileUtils.ln\_s?

**URL:** <https://www.ruby-forum.com/t/bug-in-fileutils-ln-s/170155>\
**Category:** Ruby\
**Created:** [June 12, 2009, 11:57pm UTC](https://www.ruby-forum.com/t/bug-in-fileutils-ln-s/170155 "2009-06-12T23:57:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joel\_VanderWerf](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e19b73/32.png) [@Joel\_VanderWerf](https://www.ruby-forum.com/u/Joel_VanderWerf)\
**Post date:** [June 12, 2009, 11:57pm UTC](https://www.ruby-forum.com/t/bug-in-fileutils-ln-s/170155/1 "2009-06-12T23:57:28Z")

</div>

FileUtils.ln\_s is supposed to do this:

```
  ln_s(old, new, options = {})

  Creates a symbolic link new which points to old. If new already
  exists and it is a directory, creates a symbolic link +new/old+.
  If new already exists and it is not a directory, raises
  Errno::EEXIST. But if :force option is set, overwrite new.

```

But in this case something is wrong:

$ mkdir foo  
$ echo 1\>t.rb  
$ ruby -r fileutils -e ‘FileUtils.ln\_s “t.rb”, “foo/t.rb”’  
$ ls -l foo  
total 0  
lrwxrwxrwx 1 vjoel vjoel 4 2009-06-12 14:47 t.rb -\> t.rb

Why is this a cyclic link?

However, if the _old_ filename is in /tmp, there is no problem:

$ rm foo/t.rb  
rm: remove symbolic link `foo/t.rb’? y  
$ ruby -r fileutils -e ‘FileUtils.ln\_s “/tmp/t.rb”, “foo/t.rb”’  
$ ls -l foo  
total 0  
lrwxrwxrwx 1 vjoel vjoel 9 2009-06-12 14:48 t.rb -\> /tmp/t.rb

This is with:

$ ruby -v  
ruby 1.8.6 (2008-08-11 patchlevel 287) [i686-linux]

---

<div class="post-metadata">

**Author:** ![Joel\_VanderWerf](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e19b73/32.png) [@Joel\_VanderWerf](https://www.ruby-forum.com/u/Joel_VanderWerf)\
**Post date:** [June 13, 2009, 12:12am UTC](https://www.ruby-forum.com/t/bug-in-fileutils-ln-s/170155/2 "2009-06-13T00:12:07Z")

</div>

Joel VanderWerf wrote:

> But in this case something is wrong:
> 
> $ mkdir foo  
> $ echo 1\>t.rb  
> $ ruby -r fileutils -e ‘FileUtils.ln\_s “t.rb”, “foo/t.rb”’  
> $ ls -l foo  
> total 0  
> lrwxrwxrwx 1 vjoel vjoel 4 2009-06-12 14:47 t.rb -\> t.rb
> 
> Why is this a cyclic link?

Bah, that’s the way ln(1) behaves, and I forgot. Moral of the story,  
it’s a _symbolic_ link; #ln\_s just creates a link to the string you give  
it, without relativizing to the current dir or anything.
