On Jun 5, 4:31 pm, Tim Caswell <[email protected]> wrote: > Using the canWrite function from vfs-local, you can do it with a simple > stat.https://github.com/c9/vfs/blob/master/local/localfs.js#L19-23 > > function canWrite(owner, inGroup, mode) { > return owner && (mode & 00200) || // User is owner and owner can write. > inGroup && (mode & 00020) || // User is in group and group can write. > (mode & 00002); // Anyone can write. > > } > > Then in your code do: > > fs.stat(file, function (err, stat) { > if (err) { /* handle error */ } > if (canWrite(process.uid === stat.uid, process.gid === stat.gid, > stat.mode)) { > // you can write! > } > > }); > > I'm assuming you mean if the current owner can write. Things get more > complicated if you are running as root and want to see if some arbitrary > uid/gid can write because then you have to check for execute/search access > in all the parent directories. In that case you would need something > likehttps://github.com/c9/vfs/blob/master/local/localfs.js#L104-124
I can think of a couple of other exceptions :-) - The directory resides on a read-only mount - You are using an operating system that uses ACLs like Windows or Solaris I don't think there's a generic solution to this problem. You should probably just try :-) -- Job Board: http://jobs.nodejs.org/ Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines You received this message because you are subscribed to the Google Groups "nodejs" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/nodejs?hl=en?hl=en
