diff --git a/atom/common/lib/asar.coffee b/atom/common/lib/asar.coffee index f7eeceb3f3..2373385f75 100644 --- a/atom/common/lib/asar.coffee +++ b/atom/common/lib/asar.coffee @@ -18,6 +18,7 @@ process.on 'exit', -> # Separate asar package's path from full path. splitPath = (p) -> + return [false] if process.noAsar # shortcut to disable asar. return [false] if typeof p isnt 'string' return [true, p, ''] if p.substr(-5) is '.asar' p = path.normalize p diff --git a/docs/api/process.md b/docs/api/process.md index 22fe452b0c..620ad6dc93 100644 --- a/docs/api/process.md +++ b/docs/api/process.md @@ -31,11 +31,18 @@ process.once('loaded', function() { }); ``` +## Properties + +### `process.noAsar` + +Setting this to `true` can disable the support for `asar` archives in Node's +built-in modules. + ## Methods The `process` object has the following method: -### `process.hang` +### `process.hang()` Causes the main thread of the current process hang. diff --git a/docs/tutorial/application-packaging.md b/docs/tutorial/application-packaging.md index c6e0ae3c41..b42a2f9298 100644 --- a/docs/tutorial/application-packaging.md +++ b/docs/tutorial/application-packaging.md @@ -103,6 +103,14 @@ var originalFs = require('original-fs'); originalFs.readFileSync('/path/to/example.asar'); ``` +You can also set `process.noAsar` to `true` to disable the support for `asar` in +the `fs` module: + +```javascript +process.noAsar = true; +fs.readFileSync('/path/to/example.asar'); +``` + ## Limitations on Node API Even though we tried hard to make `asar` archives in the Node API work like diff --git a/spec/asar-spec.coffee b/spec/asar-spec.coffee index af39fa3ec5..b7a62f8eea 100644 --- a/spec/asar-spec.coffee +++ b/spec/asar-spec.coffee @@ -423,6 +423,41 @@ describe 'asar package', -> p = path.join fixtures, 'asar', 'unpack.asar', 'a.txt' assert.equal internalModuleReadFile(p).toString().trim(), 'a' + describe 'process.noAsar', -> + beforeEach -> + process.noAsar = true + afterEach -> + process.noAsar = false + + it 'disables asar support in sync API', -> + file = path.join fixtures, 'asar', 'a.asar', 'file1' + dir = path.join fixtures, 'asar', 'a.asar', 'dir1' + assert.throws (-> fs.readFileSync file), /ENOTDIR/ + assert.throws (-> fs.lstatSync file), /ENOTDIR/ + assert.throws (-> fs.realpathSync file), /ENOTDIR/ + assert.throws (-> fs.readdirSync dir), /ENOTDIR/ + + it 'disables asar support in async API', (done) -> + file = path.join fixtures, 'asar', 'a.asar', 'file1' + dir = path.join fixtures, 'asar', 'a.asar', 'dir1' + fs.readFile file, (error) -> + assert.equal error.code, 'ENOTDIR' + fs.lstat file, (error) -> + assert.equal error.code, 'ENOTDIR' + fs.realpath file, (error) -> + assert.equal error.code, 'ENOTDIR' + fs.readdir dir, (error) -> + assert.equal error.code, 'ENOTDIR' + done() + + it 'treats *.asar as normal file', -> + originalFs = require 'original-fs' + asar = path.join fixtures, 'asar', 'a.asar' + content1 = fs.readFileSync asar + content2 = originalFs.readFileSync asar + assert.equal content1.compare(content2), 0 + assert.throws (-> fs.readdirSync asar), /ENOTDIR/ + describe 'asar protocol', -> url = require 'url'