Ultimately what I would like to do is determine if a directory or file is writable by the current user. Looking at the Filesystem commands there is uperm()
, gperm()
, and operm()
which at first blush look like exactly what I need. However to determine if uperm()
is me I need to know my user ID so that I can compare it with the owner ID of the file. Likewise with gperm()
I would need to know if one of my groups match the group of the file system object.
I haven’t been able to find a function in Julia that returns the user’s ID…nor anything about the groups the user belongs to. I would like functions that work in both Linux and Windows so I would prefer something in Julia (or a package) rather than executing external commands.
I would like to do this before I start doing some expensive operations so that I know I can save the results. And yes, with the behavior of this application it is entirely possible the user pointed me at a directory/file they do not have write access to. So it is a situation I need to handle.
Alternate solutions for testing the directory I’ve come up with, is first I could try to create an empty file in the directory, if that works, then I have write access. Or, and I like this better, I believe I could just touch()
the directory, if that works, we should be good to go from a directory standpoint.
The file solution is trickier. I could use touch()
or even just try to open the file for write access. But both of those would update the last modified time. And I don’t want to update the last modified time before I actually have the data to modify the file with.
Anyone have any suggestions?