On 14 September 2012, Kowshik Prakasam said:
> Is there an easier way to find if a file pointed to by a path is readable?
The traditional POSIX call is access(). However, it's prone to race
conditions: between the time you check if a file is readable by
calling access() and then actually open() it, its mode could have
changed. So open() can still fail, so you have to handle the error
there anyways, so why bother with the access() call?
I guess that's why Go's os package doesn't seem to have an Access()
function.
The usual solution is just open() the file and deal with the
consequences. There's no need to stat() it: if open() fails, you can't
read the file.
Disclaimer: I know my way around Unix/C/Python quite well, but I'm a
Go newbie. I might have missed something.
Greg
--
Greg Ward
http://www.gerg.ca/
Earn cash in your spare time -- blackmail your friends!