Project

General

Profile

Actions

Bug #10865

closed

FileUtils.mv doesn't rename windows directories across volumes/partitions.

Added by ksubrama (Kartik Cating-Subramanian) about 9 years ago. Updated about 9 years ago.

Status:
Closed
Target version:
-
ruby -v:
ruby 2.1.5p273 (2014-11-13 revision 48405) [x64-mingw32]
[ruby-core:68162]

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?

Related: https://bugs.ruby-lang.org/issues/8109

Actions #1

Updated by nobu (Nobuyoshi Nakada) about 9 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

Applied in changeset r49634.


win32.c: EXDEV for directory

  • win32/win32.c (wrename): return EXDEV if moving a directory to
    another drive, since MoveFileExW does not set proper error code.
    [ruby-core:68162] [Bug #10865]

Updated by usa (Usaku NAKAMURA) about 9 years ago

  • Backport changed from 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN to 2.0.0: REQUIRED, 2.1: REQUIRED, 2.2: REQUIRED

Updated by naruse (Yui NARUSE) about 9 years ago

  • Backport changed from 2.0.0: REQUIRED, 2.1: REQUIRED, 2.2: REQUIRED to 2.0.0: REQUIRED, 2.1: REQUIRED, 2.2: DONE

ruby_2_2 r49672 merged revision(s) 49634,49658,49663.

Actions #4

Updated by usa (Usaku NAKAMURA) about 9 years ago

  • Backport changed from 2.0.0: REQUIRED, 2.1: REQUIRED, 2.2: DONE to 2.0.0: REQUIRED, 2.1: DONE, 2.2: DONE

ruby_2_1 r50290 merged revision(s) 49634,49658,49663.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0