Find.find() doesn't work with broken symlinks

R

robertlaferla

Find.find() seems to filter out broken symlinks. I was hoping to use it to get a recursive list of files in directory so I could run various tests on each file (like whether or not a symlink points to a valid file)

What can I use instead of Find.find()? Is there a better way?

def testsymlinks(srcpath)
Find.find(srcpath) do |path|
if File.symlink?(path)
begin
File.stat(path)
rescue Exception => e
$stderr.puts "The symlink " + path + " does not point to a valid file. Please check that you have all your network volumes mounted."
exit(-1)
end
end
end
end
 
S

Stefano Crocco

Alle luned=EC 26 marzo 2007, (e-mail address removed) ha scritto:
Find.find() seems to filter out broken symlinks. I was hoping to use it = to
get a recursive list of files in directory so I could run various tests on
each file (like whether or not a symlink points to a valid file)

What can I use instead of Find.find()? Is there a better way?

def testsymlinks(srcpath)
Find.find(srcpath) do |path|
if File.symlink?(path)
begin
File.stat(path)
rescue Exception =3D> e
$stderr.puts "The symlink " + path + " does not point to a
valid file. Please check that you have all your network volumes mounted."
exit(-1)
end
end
end
end

Are you sure of this? I tried a small setup (made a directory, created a fi=
le=20
and made a symlink to it, then removed the file) and it works. Find.find=20
passes the broken symlink to the block and File.stat raises a SystemCall=20
error (Errno::ENOENT). I'm running ruby 1.8.6 on gentoo linux.

Stefano
 

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

Forum statistics

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

Latest Threads

Top