]> khamidou — GitHub mirrors - electron.git/commitdiff
asar: Add support in fs.realpath
authorCheng Zhao <zcbenz@gmail.com>
Tue, 30 Sep 2014 06:57:49 +0000 (14:57 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Tue, 30 Sep 2014 06:57:49 +0000 (14:57 +0800)
atom/common/lib/asar.coffee

index 665e759b34bd1049fe38f7a701aaae11c1fdd534..114e1942f133213e1fe4c690d15b17d2424d83cb 100644 (file)
@@ -122,6 +122,25 @@ fs.realpathSync = (p) ->
 
   path.join realpathSync(asarPath), real
 
+realpath = fs.realpath
+fs.realpath = (p, cache, callback) ->
+  [isAsar, asarPath, filePath] = splitPath p
+  return realpath.apply this, arguments unless isAsar
+
+  if typeof cache is 'function'
+    callback = cache
+    cache = undefined
+
+  archive = getOrCreateArchive asarPath
+  return callback new Error("Invalid package #{asarPath}") unless archive
+
+  real = archive.realpath filePath
+  return callback createNotFoundError(asarPath, filePath) unless real
+
+  realpath asarPath, (err, p) ->
+    return callback err if err
+    callback null, path.join(p, real)
+
 exists = fs.exists
 fs.exists = (p, callback) ->
   [isAsar, asarPath, filePath] = splitPath p