From: Kent Dahl Date: 2005-01-10T06:01:23+09:00 Subject: Re: Fileutils::copy_entry() won't copy symlinks without dereferencing Andrew Walrond wrote: > "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 true if stat is a symbolic link, * false if it isn't or if the operating system doesn't * support this feature. As File::stat automatically * follows symbolic links, symlink? will always be * false for an object returned by * File::stat. * * 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 -- Kent Dahl