s3_file icon indicating copy to clipboard operation
s3_file copied to clipboard

Permission Denied on windows server on Fileutils.mv

Open pkazi opened this issue 4 years ago • 0 comments

Getting below error on Windows when s3_file downloads the file to temp location and tries to move it to actual remote path.

Error -

>>>> Caused by Errno::EACCES: Permission denied @ rb_file_s_rename - (C:/Windows/Temp/rest-client.20200608-8736-1lxy3l2, C:/chef/cache/cloud_resource-0.1.6.gem)
C:/opscode/chef/embedded/lib/ruby/gems/2.5.0/gems/fileutils-1.4.1/lib/fileutils.rb:548:in `rename'
C:/opscode/chef/embedded/lib/ruby/gems/2.5.0/gems/fileutils-1.4.1/lib/fileutils.rb:548:in `block in mv'
C:/opscode/chef/embedded/lib/ruby/gems/2.5.0/gems/fileutils-1.4.1/lib/fileutils.rb:1588:in `block in fu_each_src_dest'
C:/opscode/chef/embedded/lib/ruby/gems/2.5.0/gems/fileutils-1.4.1/lib/fileutils.rb:1604:in `fu_each_src_dest0'
C:/opscode/chef/embedded/lib/ruby/gems/2.5.0/gems/fileutils-1.4.1/lib/fileutils.rb:1586:in `fu_each_src_dest'
C:/opscode/chef/embedded/lib/ruby/gems/2.5.0/gems/fileutils-1.4.1/lib/fileutils.rb:539:in `mv'
C:/chef/cache/cookbooks/s3_file/providers/default.rb:83:in `block in class_from_file'
(eval):2:in `block in action_create'
C:

It is because of we are passing raw_response = true on RestClient.Request.execute here

And in raw_response, that tempfile is being opened, not closed - https://github.com/rest-client/rest-client/blob/v1.7.3/lib/restclient/raw_response.rb#L24-L27

As a fix, had to add this in providers/default.rb

      res_file = response.file
      res_file.close unless res_file.closed?
      ::FileUtils.mv(res_file.path, new_resource.path)

s3_file cookbook version - 2.8.5

pkazi avatar Jun 09 '20 06:06 pkazi