Make some APIs work with archive.copyFileOut API.
This commit is contained in:
parent
fc8ff314e2
commit
38f83cacf9
2 changed files with 23 additions and 9 deletions
|
@ -4,6 +4,8 @@
|
|||
|
||||
#include "atom/common/asar/scoped_temporary_file.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "base/file_util.h"
|
||||
#include "base/threading/thread_restrictions.h"
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
asar = process.atomBinding 'asar'
|
||||
child_process = require 'child_process'
|
||||
fs = require 'fs'
|
||||
path = require 'path'
|
||||
util = require 'util'
|
||||
|
@ -218,10 +219,13 @@ fs.readdirSync = (p) ->
|
|||
|
||||
files
|
||||
|
||||
dlopen = process.dlopen
|
||||
require('module')._extensions['.node'] = process.dlopen = (module, p) ->
|
||||
# Override APIs that rely on passing file path instead of content to C++.
|
||||
overrideAPI = (module, name, arg = 0) ->
|
||||
old = module[name]
|
||||
module[name] = ->
|
||||
p = arguments[arg]
|
||||
[isAsar, asarPath, filePath] = splitPath p
|
||||
return dlopen.apply this, arguments unless isAsar
|
||||
return old.apply this, arguments unless isAsar
|
||||
|
||||
archive = getOrCreateArchive asarPath
|
||||
throw new Error("Invalid package #{asarPath}") unless archive
|
||||
|
@ -229,4 +233,12 @@ require('module')._extensions['.node'] = process.dlopen = (module, p) ->
|
|||
newPath = archive.copyFileOut filePath
|
||||
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'
|
||||
|
|
Loading…
Add table
Reference in a new issue