Project

General

Profile

Actions

Bug #12892

closed

FileUtils::cp_r() raises RuntimeError "unknown file type" instead of Errno::ENOENT "No such file or directory" for non-existent source path

Added by zinga (Patrick Zingerle) over 5 years ago. Updated over 5 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
ruby -v:
2.1.10p492
[ruby-core:77885]

Description

In Ruby 1.9.3 both FileUtils.cp(src, dst) and FileUtils.cp_r(src, dst) raised Errno::ENOENT "No such file or directory" for a non-existent src path (which is correct behaviour imho).

At least since Ruby 2.1.0 FileUtils.cp_r(src, dst) raises RuntimeError "unknown file type" for non-existent src path whereas FileUtils.cp(src, dst) still behaves like before.

$ ruby -v
ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-linux]

$ ruby -rfileutils -e 'FileUtils.cp("/non/existent", "/tmp")'
/usr/lib/ruby/1.9.1/fileutils.rb:1515:in `stat': No such file or directory - /non/existent (Errno::ENOENT)
	from /usr/lib/ruby/1.9.1/fileutils.rb:1515:in `block in fu_each_src_dest'
	from /usr/lib/ruby/1.9.1/fileutils.rb:1529:in `fu_each_src_dest0'
	from /usr/lib/ruby/1.9.1/fileutils.rb:1513:in `fu_each_src_dest'
	from /usr/lib/ruby/1.9.1/fileutils.rb:395:in `cp'
	from -e:1:in `<main>'

$ ruby -rfileutils -e 'FileUtils.cp_r("/non/existent", "/tmp")'
/usr/lib/ruby/1.9.1/fileutils.rb:1515:in `stat': No such file or directory - /non/existent (Errno::ENOENT)
	from /usr/lib/ruby/1.9.1/fileutils.rb:1515:in `block in fu_each_src_dest'
	from /usr/lib/ruby/1.9.1/fileutils.rb:1529:in `fu_each_src_dest0'
	from /usr/lib/ruby/1.9.1/fileutils.rb:1513:in `fu_each_src_dest'
	from /usr/lib/ruby/1.9.1/fileutils.rb:436:in `cp_r'
	from -e:1:in `<main>'
$ ruby -v
ruby 2.1.10p492 (2016-04-01 revision 54464) [x86_64-linux]

$ ruby -rfileutils -e 'FileUtils.cp("/non/existent", "/tmp")'
/usr/lib64/ruby/2.1.0/fileutils.rb:1401:in `initialize': No such file or directory @ rb_sysopen - /non/existent (Errno::ENOENT)
	from /usr/lib64/ruby/2.1.0/fileutils.rb:1401:in `open'
	from /usr/lib64/ruby/2.1.0/fileutils.rb:1401:in `copy_file'
	from /usr/lib64/ruby/2.1.0/fileutils.rb:483:in `copy_file'
	from /usr/lib64/ruby/2.1.0/fileutils.rb:400:in `block in cp'
	from /usr/lib64/ruby/2.1.0/fileutils.rb:1579:in `block in fu_each_src_dest'
	from /usr/lib64/ruby/2.1.0/fileutils.rb:1593:in `fu_each_src_dest0'
	from /usr/lib64/ruby/2.1.0/fileutils.rb:1577:in `fu_each_src_dest'
	from /usr/lib64/ruby/2.1.0/fileutils.rb:399:in `cp'
	from -e:1:in `<main>'

$ ruby -rfileutils -e 'FileUtils.cp_r("/non/existent", "/tmp")'
/usr/lib64/ruby/2.1.0/fileutils.rb:1396:in `copy': unknown file type: /non/existent (RuntimeError)
	from /usr/lib64/ruby/2.1.0/fileutils.rb:469:in `block in copy_entry'
	from /usr/lib64/ruby/2.1.0/fileutils.rb:1506:in `call'
	from /usr/lib64/ruby/2.1.0/fileutils.rb:1506:in `wrap_traverse'
	from /usr/lib64/ruby/2.1.0/fileutils.rb:466:in `copy_entry'
	from /usr/lib64/ruby/2.1.0/fileutils.rb:441:in `block in cp_r'
	from /usr/lib64/ruby/2.1.0/fileutils.rb:1579:in `block in fu_each_src_dest'
	from /usr/lib64/ruby/2.1.0/fileutils.rb:1593:in `fu_each_src_dest0'
	from /usr/lib64/ruby/2.1.0/fileutils.rb:1577:in `fu_each_src_dest'
	from /usr/lib64/ruby/2.1.0/fileutils.rb:440:in `cp_r'
	from -e:1:in `<main>'

If I am not mistaken this was caused by this code change https://github.com/ruby/ruby/commit/c2eac0e78c35fc7c23c4ec7024d7555b31d7bae6#diff-08dc84a402724fc771f40b6bddddc546L1563 and is still the same in trunk.

So maybe it would make sense to call Entry_#lstat() first in Entry_#copy()?

Actions #1

Updated by nobu (Nobuyoshi Nakada) over 5 years ago

  • Status changed from Open to Closed

Applied in changeset r56551.


fileutils.rb: fix error for non-existent entry

  • lib/fileutils.rb (FileUtils::Entry_#copy): ensure that the
    source entry exists first, to fix error for non-existent entry.
    [ruby-core:77885] [Bug #12892]
Actions

Also available in: Atom PDF