I was playing with some ruby the other day and I wrote the following code
File.open(my_file, "w+") do | fh |
begin
fh.readonly = true <--------Exception thrown here
ensure
fh.close
end
end
this does not work as it throws EACCES because the file is readonly, if I change the open flag to “r” this works just fine. To me this is counter intuitive because I thought opening it with “r” meant i’d only be able to read the file, not change attributes.
I am using win32-file (0.6.6) with ruby 1.8.7 (not upgradable for current project), is this normal behaviour a quirk of the win-32 file gem or just a bug that I am able to code around.
In order to set the readonly bit to true I must open with w+ which seems much more sensible
A bit more info is that this test was performed on Windows Server 2003 64-bit, just in case that makes a diff.
I eventually found out what this was, there was another process locking the directory with an exclusive lock on the filesystem, It didn’t show up with processexplorer but i noticed in my log something logging that directory, I stopped the service and bam it worked.