Issue #12585 has been updated by Nobuyoshi Nakada.

Status changed from Open to Third Party's Issue

Windows disallows removing open file unless it is opened with `FILE_SHARE_DELETE` flag.
Close `file` before `FileUtils.move`.

----------------------------------------
Bug #12585: FileUtils.move leads to rb_file_s_rename Errno::EACCES: Permission denied on Windows
https://bugs.ruby-lang.org/issues/12585#change-59616

* Author: Toby Murray
* Status: Third Party's Issue
* Priority: Normal
* Assignee: 
* ruby -v: ruby 2.3.0p0 (2015-12-25 revision 53290) [x64-mingw32]
* Backport: 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: UNKNOWN
----------------------------------------
In Windows 10, running as administrator:

~~~
 C:\tools\ruby\23-x64\bin\irb.cmd
irb(main):001:0> require 'fileutils'
=> true
irb(main):002:0> FileUtils.mkdir("first_directory")
=> ["first_directory"]
irb(main):003:0> FileUtils.mkdir("second_directory")
=> ["second_directory"]
irb(main):004:0> FileUtils.touch(File.join("first_directory", "test_file"))
=> ["first_directory/test_file"]
irb(main):005:0> file = File.new(File.join("first_directory", "test_file"))
=> #<File:first_directory/test_file>
irb(main):006:0> FileUtils.move(file, "second_directory")
Errno::EACCES: Permission denied @ rb_file_s_rename - (first_directory/test_file, second_directory/test_file)
        from C:/tools/ruby/23-x64/lib/ruby/2.3.0/fileutils.rb:528:in `rename'
        from C:/tools/ruby/23-x64/lib/ruby/2.3.0/fileutils.rb:528:in `block in mv'
        from C:/tools/ruby/23-x64/lib/ruby/2.3.0/fileutils.rb:1571:in `block in fu_each_src_dest'
        from C:/tools/ruby/23-x64/lib/ruby/2.3.0/fileutils.rb:1585:in `fu_each_src_dest0'
        from C:/tools/ruby/23-x64/lib/ruby/2.3.0/fileutils.rb:1569:in `fu_each_src_dest'
        from C:/tools/ruby/23-x64/lib/ruby/2.3.0/fileutils.rb:517:in `mv'
        from (irb):6
        from C:/tools/ruby/23-x64/bin/irb.cmd:19:in `<main>'
~~~

I've tried various invocations of `FileUtils.move`, passing file/directory objects or strings, and everything seems to end up the same. Am I using this incorrectly?

----

It appears I was using this incorrectly. `File.new` actually opens the file, which prevents it from being moved. If that's as intended, I guess this is not a bug. 



-- 
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>