Make some APIs work with archive.copyFileOut API.

This commit is contained in:
Cheng Zhao 2014-09-25 23:25:17 +08:00
parent fc8ff314e2
commit 38f83cacf9
2 changed files with 23 additions and 9 deletions

View file

@ -4,6 +4,8 @@
#include "atom/common/asar/scoped_temporary_file.h" #include "atom/common/asar/scoped_temporary_file.h"
#include <vector>
#include "base/file_util.h" #include "base/file_util.h"
#include "base/threading/thread_restrictions.h" #include "base/threading/thread_restrictions.h"

View file

@ -1,4 +1,5 @@
asar = process.atomBinding 'asar' asar = process.atomBinding 'asar'
child_process = require 'child_process'
fs = require 'fs' fs = require 'fs'
path = require 'path' path = require 'path'
util = require 'util' util = require 'util'
@ -218,15 +219,26 @@ fs.readdirSync = (p) ->
files files
dlopen = process.dlopen # Override APIs that rely on passing file path instead of content to C++.
require('module')._extensions['.node'] = process.dlopen = (module, p) -> overrideAPI = (module, name, arg = 0) ->
[isAsar, asarPath, filePath] = splitPath p old = module[name]
return dlopen.apply this, arguments unless isAsar module[name] = ->
p = arguments[arg]
[isAsar, asarPath, filePath] = splitPath p
return old.apply this, arguments unless isAsar
archive = getOrCreateArchive asarPath archive = getOrCreateArchive asarPath
throw new Error("Invalid package #{asarPath}") unless archive throw new Error("Invalid package #{asarPath}") unless archive
newPath = archive.copyFileOut filePath newPath = archive.copyFileOut filePath
throw createNotFoundError(asarPath, filePath) unless newPath throw createNotFoundError(asarPath, filePath) unless newPath
dlopen module, newPath arguments[arg] = newPath
old.apply this, arguments
overrideAPI process, 'dlopen', 1
overrideAPI require('module')._extensions, '.node', 1
overrideAPI fs, 'open'
overrideAPI fs, 'openSync'
overrideAPI child_process, 'fork'
overrideAPI child_process, 'execFile'