From b87dfb964cd8121e551009f24a95aeb4afa3f017 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 30 Sep 2014 14:57:49 +0800 Subject: [PATCH] asar: Add support in fs.realpath --- atom/common/lib/asar.coffee | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/atom/common/lib/asar.coffee b/atom/common/lib/asar.coffee index 665e759b34..114e1942f1 100644 --- a/atom/common/lib/asar.coffee +++ b/atom/common/lib/asar.coffee @@ -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