Fileutils.cp bug?

Discussion in 'Ruby' started by Chad Fowler, Nov 17, 2003.

  1. Chad Fowler

    Chad Fowler Guest

    I'm experiencing the following behavior in the latest CVS copy of ruby on
    both Windows and Linux. I think it's a bug.

    [chad@ns1 chad]$ cat test
    Goodbye Cruel World!
    [chad@ns1 chad]$ ruby -rfileutils -e 'FileUtils.cp("test", "test")'

    [chad@ns1 chad]$ cat test
    [chad@ns1 chad]$ ls -l test
    -rw-rw-r-- 1 chad chad 0 Nov 17 08:35 test
    [chad@ns1 chad]$


    I would suggest the following small change.

    Do others agree that this is a bug?

    Thanks,
    Chad




    Index: fileutils.rb
    ===================================================================
    RCS file: /src/ruby/lib/fileutils.rb,v
    retrieving revision 1.22
    diff -u -c -r1.22 fileutils.rb
    cvs server: conflicting specifications of output style
    *** fileutils.rb 30 Oct 2003 09:36:39 -0000 1.22
    --- fileutils.rb 17 Nov 2003 13:11:43 -0000
    ***************
    *** 312,317 ****
    --- 312,318 ----
    return if options[:noop]

    fu_each_src_dest(src, dest) do |s,d|
    + raise ArgumentError, "`#{src}' and `#{dest}' are the same file"
    unless (
    src != dest)
    fu_preserve_attr(options[:preserve], s, d) {
    copy_file s, d
    }
     
    Chad Fowler, Nov 17, 2003
    #1
    1. Advertising

  2. Chad Fowler

    Wejn Guest

    Hi,

    On Mon, 17 Nov 2003, Chad Fowler wrote:

    > I'm experiencing the following behavior in the latest CVS copy of ruby on
    > both Windows and Linux. I think it's a bug.
    >
    > [chad@ns1 chad]$ cat test
    > Goodbye Cruel World!
    > [chad@ns1 chad]$ ruby -rfileutils -e 'FileUtils.cp("test", "test")'
    >
    > [chad@ns1 chad]$ cat test
    > [chad@ns1 chad]$ ls -l test
    > -rw-rw-r-- 1 chad chad 0 Nov 17 08:35 test
    > [chad@ns1 chad]$
    >
    >
    > I would suggest the following small change.
    >
    > Do others agree that this is a bug?


    Well, I do think it's a bug ... but the patch is not enough, imho:

    (5/wejn/ns) x$ echo "goodbye" > src
    (5/wejn/ns) x$ ruby18 -rfileutils -e 'FileUtils.cp("src", "src")'
    /usr/local/ruby-1.8.0/lib/ruby/1.8/fileutils.rb:315:in `cp': `src' and `src' are the same file (ArgumentError)
    from /usr/local/ruby-1.8.0/lib/ruby/1.8/fileutils.rb:314:in `fu_each_src_dest'
    from /usr/local/ruby-1.8.0/lib/ruby/1.8/fileutils.rb:314:in `cp'
    from -e:1

    ... ok ... but:

    (5/wejn/ns) x$ ruby18 -rfileutils -e 'FileUtils.cp("src", "./src")'
    (5/wejn/ns) x$ ls -l src
    -rw-r--r-- 1 wejn wejn 0 Nov 17 15:04 src

    ... problem :-(

    What about comparation of [dev,inode] ?

    Sincerely,
    Michal
    --
    # Michal Safranek, email:
    a=(("a".."z").to_a+["@","."]);p(("%b"%[0x645bbb83a6a496]
    ).scan(/...../).map{|x|a[Integer("0b"+x)]}.join.reverse)
     
    Wejn, Nov 17, 2003
    #2
    1. Advertising

  3. Chad Fowler

    Wejn Guest

    Hi,

    > # What about comparation of [dev,inode] ?
    >
    > Good point, Michal. I thik I need some post-RubyConf rest :)
    >
    > How about (File.expand_path("src") == File.expand_path("dest"))?


    wow ... even better :) I think it will avoid possible problems
    on Win32 (I'm not sure how stat() behaves there regarding to
    dev and inode#).

    M.
    --
    # Michal Safranek, email:
    a=(("a".."z").to_a+["@","."]);p(("%b"%[0x645bbb83a6a496]
    ).scan(/...../).map{|x|a[Integer("0b"+x)]}.join.reverse)
     
    Wejn, Nov 17, 2003
    #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. Jim Freeze

    FileUtils Bug in 1.8.0

    Jim Freeze, Apr 22, 2004, in forum: Ruby
    Replies:
    0
    Views:
    104
    Jim Freeze
    Apr 22, 2004
  2. John-Mason P. Shackelford

    FileUtils.rm_rf bug on win2k?

    John-Mason P. Shackelford, Jul 14, 2004, in forum: Ruby
    Replies:
    1
    Views:
    197
    Minero Aoki
    Aug 8, 2004
  3. Ville Mattila
    Replies:
    3
    Views:
    127
    Ville Mattila
    Oct 14, 2004
  4. Joel VanderWerf

    bug in FileUtils.ln_s ?

    Joel VanderWerf, Jun 12, 2009, in forum: Ruby
    Replies:
    1
    Views:
    127
    Joel VanderWerf
    Jun 12, 2009
  5. Luis Lavena
    Replies:
    0
    Views:
    306
    Luis Lavena
    Jul 10, 2010
Loading...

Share This Page