]> khamidou — GitHub mirrors - electron.git/commit
:bug: Fix missing execution permission bit in execFile override
authorJuan Cruz Viotti <juanchiviotti@gmail.com>
Thu, 26 Nov 2015 12:48:47 +0000 (08:48 -0400)
committerJuan Cruz Viotti <juanchiviotti@gmail.com>
Fri, 27 Nov 2015 03:30:23 +0000 (23:30 -0400)
commit585ff9062cbf92ca65fcc50607e8f2b751f9d05e
treebedfd9bfbd424c6114eb374a2007df0c174107c5
parentbf5e9e4f4d19b05cf2fed73b7efa24aa26a6c4c8
:bug: Fix missing execution permission bit in execFile override

Consider an electron application that uses `execFile` to run a script
that lives within the application code base:

```coffee
child_process = require 'child_process'
child_process.execFile __dirname + '/script.sh', (error) ->
  throw error if error?
```

An application like this will fail when being packaged in an `asar` with
an following error:

```
Error: spawn EACCES
```

Electron overrides certain `fs` functions to make them work within an
`asar` package. In the case of `execFile`, the file to be executed is
extracted from the `asar` package into a temporary file and ran from
there.

The problem is that during the extraction, the original permissions of
the file are lost.

We workaround this by:

1. Extending `asar.stat` to return whether a file is executable or not,
  which is information that's already saved in the `asar` header.

2. Setting execution permissions on the extracted file if the above
  property holds true.

Fixes: https://github.com/atom/electron/issues/3512
atom/common/api/atom_api_asar.cc
atom/common/asar/archive.cc
atom/common/asar/archive.h
atom/common/lib/asar.coffee