Bug #10865
closedFileUtils.mv doesn't rename windows directories across volumes/partitions.
Description
C:> irb
DL is deprecated, please use Fiddle
irb(main):001:0> require 'FileUtils'
=> true
irb(main):002:0> FileUtils.mkdir("foo")
=> ["foo"]
irb(main):003:0> FileUtils.mv("foo", "bar")
=> 0
irb(main):004:0> FileUtils.mkdir("foo")
=> ["foo"]
irb(main):005:0> FileUtils.mv("foo", "F:\foo")
Errno::EACCES: Permission denied @ sys_fail2 - (foo, F:\foo)
from C:/tools/ruby215/lib/ruby/2.1.0/FileUtils.rb:525:in rename' from C:/tools/ruby215/lib/ruby/2.1.0/FileUtils.rb:525:in
block in mv'
from C:/tools/ruby215/lib/ruby/2.1.0/FileUtils.rb:1579:in block in fu_each_src_dest' from C:/tools/ruby215/lib/ruby/2.1.0/FileUtils.rb:1595:in
fu_each_src_dest0'
from C:/tools/ruby215/lib/ruby/2.1.0/FileUtils.rb:1577:in fu_each_src_dest' from C:/tools/ruby215/lib/ruby/2.1.0/FileUtils.rb:514:in
mv'
from (irb):5
from C:/tools/ruby215/bin/irb:11:in `'
irb(main):006:0>
I've narrowed this down to wrename in win32.c
https://github.com/ruby/ruby/blob/fa13cb050db8091658007df77f8247ae02442e51/win32/win32.c#L4728
It uses MoveFileExW with MOVEFILE_REPLACE_EXISTING | MOVEFILE_COPY_ALLOWED
https://msdn.microsoft.com/en-us/library/windows/desktop/aa365240%28v=vs.85%29.aspx says:
""When moving a directory, the destination must be on the same drive.""
and also:
""MOVEFILE_REPLACE_EXISTING
1 (0x1)
If a file named lpNewFileName exists, the function replaces its contents with the contents of the lpExistingFileName file, provided that security requirements regarding access control lists (ACLs) are met. For more information, see the Remarks section of this topic.
This value cannot be used if lpNewFileName or lpExistingFileName names a directory.""
FileUtils seems to have some code built around handling this but it only handles EXDEV, not EACCES. Could you check to see if you are moving a file before passing in MOVEFILE_* so that the FileUtil code can continue to work?