atom/scandal

Scandal doesn't handle file permission issues

izuzak opened this issue · 0 comments

Derived from: atom/find-and-replace#197

When scandal attempts to read file contents, it just assumes that it has permission to do so here:

fd = fs.openSync(@filePath, "r")

However, in case the current process doesn't have read permissions for the file, fd is not initialized and an EACCESS exception is raised. Because of that, scandal throws a Bad argument error here:

fs.closeSync(fd)

If that finally block checks to see if fd was initialized, then the EACCESS error is propagated instead of the Bad argument error (expected).

What would be a good way to handle those EACCESS errors? Would just catching them be it, or is there something more involved (e.g. if some other part of scandal is waiting to hear back when the file was completely read)?

cc @benogle