Merge pull request #4003 from atom/asar-mkdir
Throw ENOTDIR when calling mkdir inside asar archive
This commit is contained in:
commit
4401991e15
4 changed files with 61 additions and 5 deletions
|
@ -63,6 +63,15 @@ notFoundError = (asarPath, filePath, callback) ->
|
||||||
throw error
|
throw error
|
||||||
process.nextTick -> callback error
|
process.nextTick -> callback error
|
||||||
|
|
||||||
|
# Create a ENOTDIR error.
|
||||||
|
notDirError = (callback) ->
|
||||||
|
error = new Error('ENOTDIR, not a directory')
|
||||||
|
error.code = 'ENOTDIR'
|
||||||
|
error.errno = -20
|
||||||
|
unless typeof callback is 'function'
|
||||||
|
throw error
|
||||||
|
process.nextTick -> callback error
|
||||||
|
|
||||||
# Create invalid archive error.
|
# Create invalid archive error.
|
||||||
invalidArchiveError = (asarPath, callback) ->
|
invalidArchiveError = (asarPath, callback) ->
|
||||||
error = new Error("Invalid package #{asarPath}")
|
error = new Error("Invalid package #{asarPath}")
|
||||||
|
@ -351,6 +360,24 @@ exports.wrapFsWithAsar = (fs) ->
|
||||||
|
|
||||||
if stats.isDirectory then return 1 else return 0
|
if stats.isDirectory then return 1 else return 0
|
||||||
|
|
||||||
|
# Calling mkdir for directory inside asar archive should throw ENOTDIR
|
||||||
|
# error, but on Windows it throws ENOENT.
|
||||||
|
# This is to work around the recursive looping bug of mkdirp since it is
|
||||||
|
# widely used.
|
||||||
|
if process.platform is 'win32'
|
||||||
|
mkdir = fs.mkdir
|
||||||
|
fs.mkdir = (p, mode, callback) ->
|
||||||
|
callback = mode if typeof mode is 'function'
|
||||||
|
[isAsar, asarPath, filePath] = splitPath p
|
||||||
|
return notDirError callback if isAsar and filePath.length
|
||||||
|
mkdir p, mode, callback
|
||||||
|
|
||||||
|
mkdirSync = fs.mkdirSync
|
||||||
|
fs.mkdirSync = (p, mode) ->
|
||||||
|
[isAsar, asarPath, filePath] = splitPath p
|
||||||
|
notDirError() if isAsar and filePath.length
|
||||||
|
mkdirSync p, mode
|
||||||
|
|
||||||
overrideAPI fs, 'open'
|
overrideAPI fs, 'open'
|
||||||
overrideAPI child_process, 'execFile'
|
overrideAPI child_process, 'execFile'
|
||||||
overrideAPISync process, 'dlopen', 1
|
overrideAPISync process, 'dlopen', 1
|
||||||
|
|
|
@ -374,6 +374,18 @@ describe 'asar package', ->
|
||||||
assert.equal err.code, 'ENOENT'
|
assert.equal err.code, 'ENOENT'
|
||||||
done()
|
done()
|
||||||
|
|
||||||
|
describe 'fs.mkdir', ->
|
||||||
|
it 'throws error when calling inside asar archive', (done) ->
|
||||||
|
p = path.join fixtures, 'asar', 'a.asar', 'not-exist'
|
||||||
|
fs.mkdir p, (err) ->
|
||||||
|
assert.equal err.code, 'ENOTDIR'
|
||||||
|
done()
|
||||||
|
|
||||||
|
describe 'fs.mkdirSync', ->
|
||||||
|
it 'throws error when calling inside asar archive', ->
|
||||||
|
p = path.join fixtures, 'asar', 'a.asar', 'not-exist'
|
||||||
|
assert.throws (-> fs.mkdirSync p), new RegExp('ENOTDIR')
|
||||||
|
|
||||||
describe 'child_process.fork', ->
|
describe 'child_process.fork', ->
|
||||||
child_process = require 'child_process'
|
child_process = require 'child_process'
|
||||||
|
|
||||||
|
@ -547,6 +559,13 @@ describe 'asar package', ->
|
||||||
it 'does not touch global fs object', ->
|
it 'does not touch global fs object', ->
|
||||||
assert.notEqual fs.readdir, gfs.readdir
|
assert.notEqual fs.readdir, gfs.readdir
|
||||||
|
|
||||||
|
describe 'mkdirp module', ->
|
||||||
|
mkdirp = require 'mkdirp'
|
||||||
|
|
||||||
|
it 'throws error when calling inside asar archive', ->
|
||||||
|
p = path.join fixtures, 'asar', 'a.asar', 'not-exist'
|
||||||
|
assert.throws (-> mkdirp.sync p), new RegExp('ENOTDIR')
|
||||||
|
|
||||||
describe 'native-image', ->
|
describe 'native-image', ->
|
||||||
it 'reads image from asar archive', ->
|
it 'reads image from asar archive', ->
|
||||||
p = path.join fixtures, 'asar', 'logo.asar', 'logo.png'
|
p = path.join fixtures, 'asar', 'logo.asar', 'logo.png'
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
"basic-auth": "^1.0.0",
|
"basic-auth": "^1.0.0",
|
||||||
"graceful-fs": "3.0.5",
|
"graceful-fs": "3.0.5",
|
||||||
"mocha": "2.1.0",
|
"mocha": "2.1.0",
|
||||||
|
"mkdirp": "0.5.1",
|
||||||
"multiparty": "4.1.2",
|
"multiparty": "4.1.2",
|
||||||
"q": "0.9.7",
|
"q": "0.9.7",
|
||||||
"temp": "0.8.1",
|
"temp": "0.8.1",
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
assert = require 'assert'
|
assert = require 'assert'
|
||||||
path = require 'path'
|
path = require 'path'
|
||||||
http = require 'http'
|
http = require 'http'
|
||||||
|
url = require 'url'
|
||||||
|
|
||||||
describe '<webview> tag', ->
|
describe '<webview> tag', ->
|
||||||
@timeout 10000
|
@timeout 10000
|
||||||
|
@ -261,12 +262,12 @@ describe '<webview> tag', ->
|
||||||
it 'emits when favicon urls are received', (done) ->
|
it 'emits when favicon urls are received', (done) ->
|
||||||
webview.addEventListener 'page-favicon-updated', (e) ->
|
webview.addEventListener 'page-favicon-updated', (e) ->
|
||||||
assert.equal e.favicons.length, 2
|
assert.equal e.favicons.length, 2
|
||||||
url =
|
pageUrl =
|
||||||
if process.platform is 'win32'
|
if process.platform is 'win32'
|
||||||
'file:///C:/favicon.png'
|
'file:///C:/favicon.png'
|
||||||
else
|
else
|
||||||
'file:///favicon.png'
|
'file:///favicon.png'
|
||||||
assert.equal e.favicons[0], url
|
assert.equal e.favicons[0], pageUrl
|
||||||
done()
|
done()
|
||||||
webview.src = "file://#{fixtures}/pages/a.html"
|
webview.src = "file://#{fixtures}/pages/a.html"
|
||||||
document.body.appendChild webview
|
document.body.appendChild webview
|
||||||
|
@ -281,7 +282,9 @@ describe '<webview> tag', ->
|
||||||
document.body.appendChild webview
|
document.body.appendChild webview
|
||||||
|
|
||||||
describe 'did-navigate event', ->
|
describe 'did-navigate event', ->
|
||||||
pageUrl = "file://#{fixtures}/pages/webview-will-navigate.html"
|
p = path.join fixtures, 'pages', 'webview-will-navigate.html'
|
||||||
|
p = p.replace /\\/g, '/'
|
||||||
|
pageUrl = url.format protocol: 'file', slashes: true, pathname: p
|
||||||
|
|
||||||
it 'emits when a url that leads to outside of the page is clicked', (done) ->
|
it 'emits when a url that leads to outside of the page is clicked', (done) ->
|
||||||
webview.addEventListener 'did-navigate', (e) ->
|
webview.addEventListener 'did-navigate', (e) ->
|
||||||
|
@ -293,7 +296,10 @@ describe '<webview> tag', ->
|
||||||
|
|
||||||
describe 'did-navigate-in-page event', ->
|
describe 'did-navigate-in-page event', ->
|
||||||
it 'emits when an anchor link is clicked', (done) ->
|
it 'emits when an anchor link is clicked', (done) ->
|
||||||
pageUrl = "file://#{fixtures}/pages/webview-did-navigate-in-page.html"
|
p = path.join fixtures, 'pages', 'webview-did-navigate-in-page.html'
|
||||||
|
p = p.replace /\\/g, '/'
|
||||||
|
pageUrl = url.format protocol: 'file', slashes: true, pathname: p
|
||||||
|
|
||||||
webview.addEventListener 'did-navigate-in-page', (e) ->
|
webview.addEventListener 'did-navigate-in-page', (e) ->
|
||||||
assert.equal e.url, "#{pageUrl}#test_content"
|
assert.equal e.url, "#{pageUrl}#test_content"
|
||||||
done()
|
done()
|
||||||
|
@ -310,7 +316,10 @@ describe '<webview> tag', ->
|
||||||
document.body.appendChild webview
|
document.body.appendChild webview
|
||||||
|
|
||||||
it 'emits when window.location.hash is changed', (done) ->
|
it 'emits when window.location.hash is changed', (done) ->
|
||||||
pageUrl = "file://#{fixtures}/pages/webview-did-navigate-in-page-with-hash.html"
|
p = path.join fixtures, 'pages', 'webview-did-navigate-in-page-with-hash.html'
|
||||||
|
p = p.replace /\\/g, '/'
|
||||||
|
pageUrl = url.format protocol: 'file', slashes: true, pathname: p
|
||||||
|
|
||||||
webview.addEventListener 'did-navigate-in-page', (e) ->
|
webview.addEventListener 'did-navigate-in-page', (e) ->
|
||||||
assert.equal e.url, "#{pageUrl}#test"
|
assert.equal e.url, "#{pageUrl}#test"
|
||||||
done()
|
done()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue