I started to learn chefs to manage our servers, and I came across a very strange (in my opinion) behavior in Ruby. I do not know Ruby, so it may just be a misunderstanding on my part.
The error I received was
`delete': Permission denied - [some path]/metadata.json (Errno::EACCES)
Since I knew for sure that this is not just about permissions, the next logical task is to check file locks. After digging through the appropriate code, I found that there is a method that creates a checksum for each file.
def checksum_file(file, digest) File.open(file, 'rb') { |f| checksum_io(f, digest) } end def checksum_io(io, digest) while chunk = io.read(1024 * 8) digest.update(chunk) end digest.hexdigest end
Having found this, I searched a bit and found an answer about closing files in Ruby, and it seemed that the code was really beautiful ... but it wasn’t, I tried to change the method to “block format” and it worked without errors:
def checksum_file(file, digest) File.open(file, 'rb') do |f| checksum_io(f, digest) end end
Can someone explain the difference between the two versions of the code?
- Change -
It seems that this problem only occurs on Windows and possibly only when using ruby ​​provided by ChefDK 0.3.0:
ruby 2.0.0p451 (2014-02-24) [i386-mingw32]
windows ruby
Diadistis
source share