Issue #12892 has been reported by Patrick Zingerle.

----------------------------------------
Bug #12892: FileUtils::cp_r() raises RuntimeError "unknown file type" instead of Errno::ENOENT "No such file or directory" for non-existent source path
https://bugs.ruby-lang.org/issues/12892

* Author: Patrick Zingerle
* Status: Open
* Priority: Normal
* Assignee: 
* ruby -v: 2.1.10p492
* Backport: 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: UNKNOWN
----------------------------------------
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.

~~~ text
$ 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>'
~~~

~~~ text
$ 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()?



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>