]> khamidou — GitHub mirrors - electron.git/commitdiff
Make some APIs work with archive.copyFileOut API.
authorCheng Zhao <zcbenz@gmail.com>
Thu, 25 Sep 2014 15:25:17 +0000 (23:25 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Thu, 25 Sep 2014 15:25:17 +0000 (23:25 +0800)
atom/common/asar/scoped_temporary_file.cc
atom/common/lib/asar.coffee

index e5de2861930b531c954fe56500286c7589e801ac..799f09d88d219eea21b93a5865bfff6bb701b72e 100644 (file)
@@ -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"
 
index eed88a220e45ffd1a43bd6751c3f40adf7327285..bdb14e08da7ba8ff6954666bc282d7555c68f8ec 100644 (file)
@@ -1,4 +1,5 @@
 asar = process.atomBinding 'asar'
+child_process = require 'child_process'
 fs = require 'fs'
 path = require 'path'
 util = require 'util'
@@ -218,15 +219,26 @@ fs.readdirSync = (p) ->
 
   files
 
-dlopen = process.dlopen
-require('module')._extensions['.node'] = process.dlopen = (module, p) ->
-  [isAsar, asarPath, filePath] = splitPath p
-  return dlopen.apply this, arguments unless isAsar
-
-  archive = getOrCreateArchive asarPath
-  throw new Error("Invalid package #{asarPath}") unless archive
-
-  newPath = archive.copyFileOut filePath
-  throw createNotFoundError(asarPath, filePath) unless newPath
-
-  dlopen module, newPath
+# 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 old.apply this, arguments unless isAsar
+
+    archive = getOrCreateArchive asarPath
+    throw new Error("Invalid package #{asarPath}") unless archive
+
+    newPath = archive.copyFileOut filePath
+    throw createNotFoundError(asarPath, filePath) unless 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'