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

Discussion in 'Ruby' started by robertlaferla@comcast.net, Mar 26, 2007.

  1. Guest

    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
     
    , Mar 26, 2007
    #1
    1. Advertising

  2. Alle luned=EC 26 marzo 2007, 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
     
    Stefano Crocco, Mar 26, 2007
    #2
    1. Advertising

  3. chopper wrote:
    > Is there a Rails specific list? I tried subscribing to '
    > ' but haven't been able to get a response.
    >
    > - chopper
    >


    http://www.rubyonrails.org/community

    --
    Phillip "CynicalRyan" Gawlowski

    Eek! That was supposed to be My Special Law, _MY_ special law, I tell
    you!

    T/
     
    Phillip Gawlowski, Mar 26, 2007
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Thomas Kuhlmann

    Creating symlinks with java

    Thomas Kuhlmann, Jan 28, 2004, in forum: Java
    Replies:
    2
    Views:
    575
  2. Michele Simionato

    making symlinks with distutils

    Michele Simionato, Feb 4, 2005, in forum: Python
    Replies:
    6
    Views:
    1,325
    Christos TZOTZIOY Georgiou
    Feb 4, 2005
  3. Jim
    Replies:
    0
    Views:
    337
  4. Andrew Walrond
    Replies:
    6
    Views:
    447
    Minero Aoki
    Jan 10, 2005
  5. has
    Replies:
    2
    Views:
    93
Loading...

Share This Page