From: usa@... Date: 2015-02-18T07:38:35+00:00 Subject: [ruby-core:68170] [Ruby trunk - Bug #10865] FileUtils.mv doesn't rename windows directories across volumes/partitions. Issue #10865 has been updated by Usaku NAKAMURA. Backport changed from 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN to 2.0.0: REQUIRED, 2.1: REQUIRED, 2.2: REQUIRED ---------------------------------------- Bug #10865: FileUtils.mv doesn't rename windows directories across volumes/partitions. https://bugs.ruby-lang.org/issues/10865#change-51547 * Author: Kartik Cating-Subramanian * Status: Closed * Priority: Normal * Assignee: Usaku NAKAMURA * ruby -v: ruby 2.1.5p273 (2014-11-13 revision 48405) [x64-mingw32] * Backport: 2.0.0: REQUIRED, 2.1: REQUIRED, 2.2: REQUIRED ---------------------------------------- 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? Related: https://bugs.ruby-lang.org/issues/8109 -- https://bugs.ruby-lang.org/