In your report above, if you look closely, the first error (Errno::EPERM
) is a permissions error that was raised in Ruby’s Dir.pwd
method. The second error (Errno::ENOENT
) is a no [directory] entry error that was raised in the Dir.chdir
method. So there are two places in the Ruby Core that need “some love”.
Well there are really two facets here with this situation.
- How should the Ruby Core handle it? (Is it handled correctly now?)
- How should coders (SketchUp plugins in our case) handle this situation?
A(1) The raising of the Errno::EPERM
permissions exception is the right thing to do by the Ruby Core.
But it should have been done first by Dir.chdir
before Dir.pwd
was called from within it’s block.
1a. Personally, I would argue that Dir.pwd
should just spit out the working directory path regardless of security accessibility, and the permissions exception should not get raised until an actual permissions violation occurs (in this case an attempt to change the wd to the “secure” Documents directory.)
A(2) It is the coders responsibility to trap for the Errno::EPERM
permissions exception within a rescue
clause and provide a graceful bailout, and notify the user, say via a messagebox.
You have found that a coder can successfully test for access permission to the Documents directory folders via a call to Dir.chdir
.
def documents_folder_accessible?
Dir.chdir("~/Documents") { Dir.pwd; true }
rescue Errno::EPERM, Errno::ENOENT
return false
end
ADD: MS Windows doesn’t automatically expand paths so this might be better for cross-platform …
def documents_folder_accessible?
Dir.chdir(File.expand_path("~/Documents")) { Dir.pwd; true }
rescue Errno::EPERM, Errno::ENOENT => e
puts e.inspect
return false
end
Ruby’s File
class also has some test methods. These have given mixed results for Windows platform in the past, but may work better on macOS.
File.readable?
File.readable_real?
File.writable?
File.writable_real?
It looks like some changes may need to be done in the Ruby Core, but this is not something Trimble can do. Thomas has filed bug reports for the Ruby Core in the past so he might be able to do so concerning this (if none have yet been filed.) The Ruby Core has it’s own website for filing an debate on issues.
Even if the Ruby Core backports macOS permissions fixes to 2.5 Ruby, it is not likely Trimble would recompile and re-release any SketchUp version other than the current version supporting Catalina. But this would only happen if a maintenance release was forthcoming.
As it’s very late in the year and the next major version is due, more than likely any fix for SU2019 will not happen.