Fileutils::copy_entry() won't copy symlinks without dereferencing

A

Andrew Walrond

Am I doing something stupid?? ruby-doc says

"copy_entry(src, dest, preserve = false, dereference = false)

Copies a file system entry src to dest. This method preserves
file types, c.f. FIFO, device files, directory.…

Both of src and dest must be a path name. src must exist,
dest must not exist.

If preserve is true, this method preserves owner, group and
permissions. If dereference is true, this method copies a
target of symbolic link instead of a symbolic link itself. "

But I cannot get a symlink to copy as a symlink. Example:

andrew@orac apw $ ruby --version
ruby 1.8.2 (2004-12-15) [x86_64-linux]
andrew@orac apw $ ls -l /etc/ld.so.conf
lrwxrwxr-x 1 root root 27 Dec 16 23:28 /etc/ld.so.conf -> /pkg/glibc.1/etc/ld.so.conf
andrew@orac apw $ irb
irb(main):001:0> require "fileutils"
=> true
irb(main):002:0> FileUtils.copy_entry("/etc/ld.so.conf","ld.so.conf")
=> nil
irb(main):003:0> quit
andrew@orac apw $ ls -l
total 4
-rw-r--r-- 1 andrew users 2469 Jan 9 20:07 ld.so.conf
andrew@orac apw $

Any suggestions?

Andrew Walrond
 
L

leon breedt

But I cannot get a symlink to copy as a symlink. Example:
This appears to be a bug.

In my version of Ruby, File.stat('/some/symlink').file? returns true
if the symlink points to a file.

If you look at fileutils.rb, you'll see the case statement in
CopyContext_#_copy_entry puts the st.file? condition before the
st.symlink? condition, so st.symlink? will never be true, and
#_copy_content will always be used.

Leon
 
K

Kent Dahl

Andrew said:
"copy_entry(src, dest, preserve = false, dereference = false)
[...]

But I cannot get a symlink to copy as a symlink. Example:

Same problem here on ruby 1.8.2 (2004-12-25) [x86_64-linux].

FileUtils appeared to be correct at first glance, the problem was due to
File.stat(filename).symlink? not returning true for symlinks.

But then I saw this tidbit in file.c:

* call-seq:
* stat.symlink? => true or false
*
* Returns <code>true</code> if <i>stat</i> is a symbolic link,
* <code>false</code> if it isn't or if the operating system doesn't
* support this feature. As <code>File::stat</code> automatically
* follows symbolic links, <code>symlink?</code> will always be
* <code>false</code> for an object returned by
* <code>File::stat</code>.
*
* File.symlink("testfile", "alink") #=> 0
* File.stat("alink").symlink? #=> false
* File.lstat("alink").symlink? #=> true

Should FileUtils use lstat everywhere? (It does for the most part.)

As for a quick hack/workaround, just change one method after fetching the
FileUtils module:

require 'fileutils'
class FileUtils::CopyContext_
def stat(path)
@stat ||= ::File.lstat(path)
end
end
FileUtils.copy_entry( 'link', 'link2' )

This script makes another symlink to whatever 'link' pointed to, on my
system.

HTH
 
M

Minero Aoki

Hi,

In mail "Fileutils::copy_entry() won't copy symlinks without dereferencing"
Andrew Walrond said:
Am I doing something stupid?? ruby-doc says
(snip...)

target of symbolic link instead of a symbolic link itself. "

But I cannot get a symlink to copy as a symlink. Example:

Sorry, this is a bug of fileutils.
It was already fixed in HEAD, but was too late for 1.8.2.
Please do not use copy_entry in this version.

Best Regards,
Minero Aoki
 
A

Andrew Walrond

Sorry, this is a bug of fileutils.
It was already fixed in HEAD, but was too late for 1.8.2.
Please do not use copy_entry in this version.

Ok. Has it reached a stable snapshot yet?

Andrew
 
M

Minero Aoki

Hi,

In mail "Re: Fileutils::copy_entry() won't copy symlinks without dereferencing"
Ok. Has it reached a stable snapshot yet?

I have committed a patch now, it will appear in next snapshot.

Best Regards,
Minreo Aoki
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top