From bf978e09e41197ef6f522ac598578b695a178806 Mon Sep 17 00:00:00 2001 From: Milan Burda Date: Wed, 2 Oct 2019 06:33:07 +0200 Subject: [PATCH] fix: allow paths to asar archives to contain the .asar extension in directories (#20342) --- lib/common/asar.js | 19 +- shell/common/api/atom_api_asar.cc | 17 + shell/common/asar/asar_util.cc | 20 +- shell/common/asar/asar_util.h | 3 +- spec-main/api-protocol-spec.ts | 4 +- spec/asar-spec.js | 320 +++++++++--------- spec/fixtures/module/no-asar.js | 2 +- spec/fixtures/no-proprietary-codecs.js | 2 +- spec/fixtures/{asar => test.asar}/a.asar | Bin spec/fixtures/{asar => test.asar}/echo.asar | Bin spec/fixtures/{asar => test.asar}/empty.asar | Bin spec/fixtures/{asar => test.asar}/file | 0 spec/fixtures/{asar => test.asar}/logo.asar | Bin spec/fixtures/{asar => test.asar}/script.asar | Bin spec/fixtures/{asar => test.asar}/unpack.asar | Bin .../unpack.asar.unpacked/a.txt | 0 .../unpack.asar.unpacked/atom.png | Bin spec/fixtures/{asar => test.asar}/video.asar | Bin spec/fixtures/{asar => test.asar}/web.asar | Bin 19 files changed, 204 insertions(+), 183 deletions(-) rename spec/fixtures/{asar => test.asar}/a.asar (100%) rename spec/fixtures/{asar => test.asar}/echo.asar (100%) rename spec/fixtures/{asar => test.asar}/empty.asar (100%) rename spec/fixtures/{asar => test.asar}/file (100%) rename spec/fixtures/{asar => test.asar}/logo.asar (100%) rename spec/fixtures/{asar => test.asar}/script.asar (100%) rename spec/fixtures/{asar => test.asar}/unpack.asar (100%) rename spec/fixtures/{asar => test.asar}/unpack.asar.unpacked/a.txt (100%) rename spec/fixtures/{asar => test.asar}/unpack.asar.unpacked/atom.png (100%) rename spec/fixtures/{asar => test.asar}/video.asar (100%) rename spec/fixtures/{asar => test.asar}/web.asar (100%) diff --git a/lib/common/asar.js b/lib/common/asar.js index 8366fb33633a..67b7b813f851 100644 --- a/lib/common/asar.js +++ b/lib/common/asar.js @@ -40,8 +40,6 @@ return newArchive } - const ASAR_EXTENSION = '.asar' - // Separate asar package's path from full path. const splitPath = archivePathOrBuffer => { // Shortcut for disabled asar. @@ -54,22 +52,7 @@ } if (typeof archivePath !== 'string') return { isAsar: false } - if (archivePath.endsWith(ASAR_EXTENSION)) { - return { isAsar: true, asarPath: archivePath, filePath: '' } - } - - archivePath = path.normalize(archivePath) - const index = archivePath.lastIndexOf(`${ASAR_EXTENSION}${path.sep}`) - if (index === -1) return { isAsar: false } - - // E.g. for "//some/path/to/archive.asar/then/internal.file"... - return { - isAsar: true, - // "//some/path/to/archive.asar" - asarPath: archivePath.substr(0, index + ASAR_EXTENSION.length), - // "then/internal.file" (with a path separator excluded) - filePath: archivePath.substr(index + ASAR_EXTENSION.length + 1) - } + return asar.splitPath(path.normalize(archivePath)) } // Convert asar archive's Stats object to fs's Stats object. diff --git a/shell/common/api/atom_api_asar.cc b/shell/common/api/atom_api_asar.cc index 8ca6a196aa0f..27df59cfd396 100644 --- a/shell/common/api/atom_api_asar.cc +++ b/shell/common/api/atom_api_asar.cc @@ -7,9 +7,11 @@ #include #include "native_mate/arguments.h" +#include "native_mate/dictionary.h" #include "native_mate/object_template_builder_deprecated.h" #include "native_mate/wrappable.h" #include "shell/common/asar/archive.h" +#include "shell/common/asar/asar_util.h" #include "shell/common/gin_converters/callback_converter.h" #include "shell/common/gin_helper/dictionary.h" #include "shell/common/native_mate_converters/file_path_converter.h" @@ -127,12 +129,27 @@ void InitAsarSupport(v8::Isolate* isolate, v8::Local require) { &asar_init_params, &asar_init_args, nullptr); } +v8::Local SplitPath(v8::Isolate* isolate, + const base::FilePath& path) { + mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate); + base::FilePath asar_path, file_path; + if (asar::GetAsarArchivePath(path, &asar_path, &file_path, true)) { + dict.Set("isAsar", true); + dict.Set("asarPath", asar_path); + dict.Set("filePath", file_path); + } else { + dict.Set("isAsar", false); + } + return dict.GetHandle(); +} + void Initialize(v8::Local exports, v8::Local unused, v8::Local context, void* priv) { gin_helper::Dictionary dict(context->GetIsolate(), exports); dict.SetMethod("createArchive", &Archive::Create); + dict.SetMethod("splitPath", &SplitPath); dict.SetMethod("initAsarSupport", &InitAsarSupport); } diff --git a/shell/common/asar/asar_util.cc b/shell/common/asar/asar_util.cc index 3e08095ff644..65ddbf2843dc 100644 --- a/shell/common/asar/asar_util.cc +++ b/shell/common/asar/asar_util.cc @@ -12,6 +12,7 @@ #include "base/lazy_instance.h" #include "base/stl_util.h" #include "base/threading/thread_local.h" +#include "base/threading/thread_restrictions.h" #include "shell/common/asar/archive.h" namespace asar { @@ -25,6 +26,17 @@ base::LazyInstance>::Leaky const base::FilePath::CharType kAsarExtension[] = FILE_PATH_LITERAL(".asar"); +std::map g_is_directory_cache; + +bool IsDirectoryCached(const base::FilePath& path) { + auto it = g_is_directory_cache.find(path); + if (it != g_is_directory_cache.end()) { + return it->second; + } + base::ThreadRestrictions::ScopedAllowIO allow_io; + return g_is_directory_cache[path] = base::DirectoryExists(path); +} + } // namespace std::shared_ptr GetOrCreateAsarArchive(const base::FilePath& path) { @@ -55,11 +67,12 @@ void ClearArchives() { bool GetAsarArchivePath(const base::FilePath& full_path, base::FilePath* asar_path, - base::FilePath* relative_path) { + base::FilePath* relative_path, + bool allow_root) { base::FilePath iter = full_path; while (true) { base::FilePath dirname = iter.DirName(); - if (iter.MatchesExtension(kAsarExtension)) + if (iter.MatchesExtension(kAsarExtension) && !IsDirectoryCached(iter)) break; else if (iter == dirname) return false; @@ -67,7 +80,8 @@ bool GetAsarArchivePath(const base::FilePath& full_path, } base::FilePath tail; - if (!iter.AppendRelativePath(full_path, &tail)) + if (!((allow_root && iter == full_path) || + iter.AppendRelativePath(full_path, &tail))) return false; *asar_path = iter; diff --git a/shell/common/asar/asar_util.h b/shell/common/asar/asar_util.h index c37f95399ada..c48336eb2c61 100644 --- a/shell/common/asar/asar_util.h +++ b/shell/common/asar/asar_util.h @@ -25,7 +25,8 @@ void ClearArchives(); // Separates the path to Archive out. bool GetAsarArchivePath(const base::FilePath& full_path, base::FilePath* asar_path, - base::FilePath* relative_path); + base::FilePath* relative_path, + bool allow_root = false); // Same with base::ReadFileToString but supports asar Archive. bool ReadFileToString(const base::FilePath& path, std::string* contents); diff --git a/spec-main/api-protocol-spec.ts b/spec-main/api-protocol-spec.ts index a324a7485275..525c90848af5 100644 --- a/spec-main/api-protocol-spec.ts +++ b/spec-main/api-protocol-spec.ts @@ -195,7 +195,7 @@ describe('protocol module', () => { }) describe('protocol.registerFileProtocol', () => { - const filePath = path.join(fixturesPath, 'asar', 'a.asar', 'file1') + const filePath = path.join(fixturesPath, 'test.asar', 'a.asar', 'file1') const fileContent = fs.readFileSync(filePath) const normalPath = path.join(fixturesPath, 'pages', 'a.html') const normalContent = fs.readFileSync(normalPath) @@ -248,7 +248,7 @@ describe('protocol module', () => { }) it('fails when sending unexist-file', async () => { - const fakeFilePath = path.join(fixturesPath, 'asar', 'a.asar', 'not-exist') + const fakeFilePath = path.join(fixturesPath, 'test.asar', 'a.asar', 'not-exist') await registerFileProtocol(protocolName, (request, callback) => callback(fakeFilePath)) await expect(ajax(protocolName + '://fake-host')).to.be.eventually.rejectedWith(Error, '404') }) diff --git a/spec/asar-spec.js b/spec/asar-spec.js index 10251169b051..5b6daab470fe 100644 --- a/spec/asar-spec.js +++ b/spec/asar-spec.js @@ -31,10 +31,11 @@ async function expectToThrowErrorWithCode (func, code) { describe('asar package', function () { const fixtures = path.join(__dirname, 'fixtures') + const asarDir = path.join(fixtures, 'test.asar') describe('node api', function () { it('supports paths specified as a Buffer', function () { - const file = Buffer.from(path.join(fixtures, 'asar', 'a.asar', 'file1')) + const file = Buffer.from(path.join(asarDir, 'a.asar', 'file1')) expect(fs.existsSync(file)).to.be.true() }) @@ -48,42 +49,42 @@ describe('asar package', function () { }) it('reads a normal file', function () { - const file1 = path.join(fixtures, 'asar', 'a.asar', 'file1') + const file1 = path.join(asarDir, 'a.asar', 'file1') expect(fs.readFileSync(file1).toString().trim()).to.equal('file1') - const file2 = path.join(fixtures, 'asar', 'a.asar', 'file2') + const file2 = path.join(asarDir, 'a.asar', 'file2') expect(fs.readFileSync(file2).toString().trim()).to.equal('file2') - const file3 = path.join(fixtures, 'asar', 'a.asar', 'file3') + const file3 = path.join(asarDir, 'a.asar', 'file3') expect(fs.readFileSync(file3).toString().trim()).to.equal('file3') }) it('reads from a empty file', function () { - const file = path.join(fixtures, 'asar', 'empty.asar', 'file1') + const file = path.join(asarDir, 'empty.asar', 'file1') const buffer = fs.readFileSync(file) expect(buffer).to.be.empty() expect(buffer.toString()).to.equal('') }) it('reads a linked file', function () { - const p = path.join(fixtures, 'asar', 'a.asar', 'link1') + const p = path.join(asarDir, 'a.asar', 'link1') expect(fs.readFileSync(p).toString().trim()).to.equal('file1') }) it('reads a file from linked directory', function () { - const p1 = path.join(fixtures, 'asar', 'a.asar', 'link2', 'file1') + const p1 = path.join(asarDir, 'a.asar', 'link2', 'file1') expect(fs.readFileSync(p1).toString().trim()).to.equal('file1') - const p2 = path.join(fixtures, 'asar', 'a.asar', 'link2', 'link2', 'file1') + const p2 = path.join(asarDir, 'a.asar', 'link2', 'link2', 'file1') expect(fs.readFileSync(p2).toString().trim()).to.equal('file1') }) it('throws ENOENT error when can not find file', function () { - const p = path.join(fixtures, 'asar', 'a.asar', 'not-exist') + const p = path.join(asarDir, 'a.asar', 'not-exist') expect(() => { fs.readFileSync(p) }).to.throw(/ENOENT/) }) it('passes ENOENT error to callback when can not find file', function () { - const p = path.join(fixtures, 'asar', 'a.asar', 'not-exist') + const p = path.join(asarDir, 'a.asar', 'not-exist') let async = false fs.readFile(p, function (error) { expect(async).to.be.true() @@ -93,14 +94,19 @@ describe('asar package', function () { }) it('reads a normal file with unpacked files', function () { - const p = path.join(fixtures, 'asar', 'unpack.asar', 'a.txt') + const p = path.join(asarDir, 'unpack.asar', 'a.txt') expect(fs.readFileSync(p).toString().trim()).to.equal('a') }) + + it('reads a file in filesystem', function () { + const p = path.resolve(asarDir, 'file') + expect(fs.readFileSync(p).toString().trim()).to.equal('file') + }) }) describe('fs.readFile', function () { it('reads a normal file', function (done) { - const p = path.join(fixtures, 'asar', 'a.asar', 'file1') + const p = path.join(asarDir, 'a.asar', 'file1') fs.readFile(p, function (err, content) { expect(err).to.be.null() expect(String(content).trim()).to.equal('file1') @@ -109,7 +115,7 @@ describe('asar package', function () { }) it('reads from a empty file', function (done) { - const p = path.join(fixtures, 'asar', 'empty.asar', 'file1') + const p = path.join(asarDir, 'empty.asar', 'file1') fs.readFile(p, function (err, content) { expect(err).to.be.null() expect(String(content)).to.equal('') @@ -118,7 +124,7 @@ describe('asar package', function () { }) it('reads from a empty file with encoding', function (done) { - const p = path.join(fixtures, 'asar', 'empty.asar', 'file1') + const p = path.join(asarDir, 'empty.asar', 'file1') fs.readFile(p, 'utf8', function (err, content) { expect(err).to.be.null() expect(content).to.equal('') @@ -127,7 +133,7 @@ describe('asar package', function () { }) it('reads a linked file', function (done) { - const p = path.join(fixtures, 'asar', 'a.asar', 'link1') + const p = path.join(asarDir, 'a.asar', 'link1') fs.readFile(p, function (err, content) { expect(err).to.be.null() expect(String(content).trim()).to.equal('file1') @@ -136,7 +142,7 @@ describe('asar package', function () { }) it('reads a file from linked directory', function (done) { - const p = path.join(fixtures, 'asar', 'a.asar', 'link2', 'link2', 'file1') + const p = path.join(asarDir, 'a.asar', 'link2', 'link2', 'file1') fs.readFile(p, function (err, content) { expect(err).to.be.null() expect(String(content).trim()).to.equal('file1') @@ -145,7 +151,7 @@ describe('asar package', function () { }) it('throws ENOENT error when can not find file', function (done) { - const p = path.join(fixtures, 'asar', 'a.asar', 'not-exist') + const p = path.join(asarDir, 'a.asar', 'not-exist') fs.readFile(p, function (err) { expect(err.code).to.equal('ENOENT') done() @@ -155,44 +161,44 @@ describe('asar package', function () { describe('fs.promises.readFile', function () { it('reads a normal file', async function () { - const p = path.join(fixtures, 'asar', 'a.asar', 'file1') + const p = path.join(asarDir, 'a.asar', 'file1') const content = await fs.promises.readFile(p) expect(String(content).trim()).to.equal('file1') }) it('reads from a empty file', async function () { - const p = path.join(fixtures, 'asar', 'empty.asar', 'file1') + const p = path.join(asarDir, 'empty.asar', 'file1') const content = await fs.promises.readFile(p) expect(String(content)).to.equal('') }) it('reads from a empty file with encoding', async function () { - const p = path.join(fixtures, 'asar', 'empty.asar', 'file1') + const p = path.join(asarDir, 'empty.asar', 'file1') const content = await fs.promises.readFile(p, 'utf8') expect(content).to.equal('') }) it('reads a linked file', async function () { - const p = path.join(fixtures, 'asar', 'a.asar', 'link1') + const p = path.join(asarDir, 'a.asar', 'link1') const content = await fs.promises.readFile(p) expect(String(content).trim()).to.equal('file1') }) it('reads a file from linked directory', async function () { - const p = path.join(fixtures, 'asar', 'a.asar', 'link2', 'link2', 'file1') + const p = path.join(asarDir, 'a.asar', 'link2', 'link2', 'file1') const content = await fs.promises.readFile(p) expect(String(content).trim()).to.equal('file1') }) it('throws ENOENT error when can not find file', async function () { - const p = path.join(fixtures, 'asar', 'a.asar', 'not-exist') + const p = path.join(asarDir, 'a.asar', 'not-exist') await expectToThrowErrorWithCode(() => fs.promises.readFile(p), 'ENOENT') }) }) describe('fs.copyFile', function () { it('copies a normal file', function (done) { - const p = path.join(fixtures, 'asar', 'a.asar', 'file1') + const p = path.join(asarDir, 'a.asar', 'file1') const dest = temp.path() fs.copyFile(p, dest, function (err) { expect(err).to.be.null() @@ -202,7 +208,7 @@ describe('asar package', function () { }) it('copies a unpacked file', function (done) { - const p = path.join(fixtures, 'asar', 'unpack.asar', 'a.txt') + const p = path.join(asarDir, 'unpack.asar', 'a.txt') const dest = temp.path() fs.copyFile(p, dest, function (err) { expect(err).to.be.null() @@ -214,14 +220,14 @@ describe('asar package', function () { describe('fs.promises.copyFile', function () { it('copies a normal file', async function () { - const p = path.join(fixtures, 'asar', 'a.asar', 'file1') + const p = path.join(asarDir, 'a.asar', 'file1') const dest = temp.path() await fs.promises.copyFile(p, dest) expect(fs.readFileSync(p).equals(fs.readFileSync(dest))).to.be.true() }) it('copies a unpacked file', async function () { - const p = path.join(fixtures, 'asar', 'unpack.asar', 'a.txt') + const p = path.join(asarDir, 'unpack.asar', 'a.txt') const dest = temp.path() await fs.promises.copyFile(p, dest) expect(fs.readFileSync(p).equals(fs.readFileSync(dest))).to.be.true() @@ -230,14 +236,14 @@ describe('asar package', function () { describe('fs.copyFileSync', function () { it('copies a normal file', function () { - const p = path.join(fixtures, 'asar', 'a.asar', 'file1') + const p = path.join(asarDir, 'a.asar', 'file1') const dest = temp.path() fs.copyFileSync(p, dest) expect(fs.readFileSync(p).equals(fs.readFileSync(dest))).to.be.true() }) it('copies a unpacked file', function () { - const p = path.join(fixtures, 'asar', 'unpack.asar', 'a.txt') + const p = path.join(asarDir, 'unpack.asar', 'a.txt') const dest = temp.path() fs.copyFileSync(p, dest) expect(fs.readFileSync(p).equals(fs.readFileSync(dest))).to.be.true() @@ -246,13 +252,13 @@ describe('asar package', function () { describe('fs.lstatSync', function () { it('handles path with trailing slash correctly', function () { - const p = path.join(fixtures, 'asar', 'a.asar', 'link2', 'link2', 'file1') + const p = path.join(asarDir, 'a.asar', 'link2', 'link2', 'file1') fs.lstatSync(p) fs.lstatSync(p + '/') }) it('returns information of root', function () { - const p = path.join(fixtures, 'asar', 'a.asar') + const p = path.join(asarDir, 'a.asar') const stats = fs.lstatSync(p) expect(stats.isFile()).to.be.false() expect(stats.isDirectory()).to.be.true() @@ -261,7 +267,7 @@ describe('asar package', function () { }) it('returns information of root with stats as bigint', function () { - const p = path.join(fixtures, 'asar', 'a.asar') + const p = path.join(asarDir, 'a.asar') const stats = fs.lstatSync(p, { bigint: false }) expect(stats.isFile()).to.be.false() expect(stats.isDirectory()).to.be.true() @@ -273,7 +279,7 @@ describe('asar package', function () { const ref2 = ['file1', 'file2', 'file3', path.join('dir1', 'file1'), path.join('link2', 'file1')] for (let j = 0, len = ref2.length; j < len; j++) { const file = ref2[j] - const p = path.join(fixtures, 'asar', 'a.asar', file) + const p = path.join(asarDir, 'a.asar', file) const stats = fs.lstatSync(p) expect(stats.isFile()).to.be.true() expect(stats.isDirectory()).to.be.false() @@ -286,7 +292,7 @@ describe('asar package', function () { const ref2 = ['dir1', 'dir2', 'dir3'] for (let j = 0, len = ref2.length; j < len; j++) { const file = ref2[j] - const p = path.join(fixtures, 'asar', 'a.asar', file) + const p = path.join(asarDir, 'a.asar', file) const stats = fs.lstatSync(p) expect(stats.isFile()).to.be.false() expect(stats.isDirectory()).to.be.true() @@ -299,7 +305,7 @@ describe('asar package', function () { const ref2 = ['link1', path.join('dir1', 'link1'), path.join('link2', 'link2')] for (let j = 0, len = ref2.length; j < len; j++) { const file = ref2[j] - const p = path.join(fixtures, 'asar', 'a.asar', file) + const p = path.join(asarDir, 'a.asar', file) const stats = fs.lstatSync(p) expect(stats.isFile()).to.be.false() expect(stats.isDirectory()).to.be.false() @@ -312,7 +318,7 @@ describe('asar package', function () { const ref2 = ['link2', path.join('dir1', 'link2'), path.join('link2', 'link2')] for (let j = 0, len = ref2.length; j < len; j++) { const file = ref2[j] - const p = path.join(fixtures, 'asar', 'a.asar', file) + const p = path.join(asarDir, 'a.asar', file) const stats = fs.lstatSync(p) expect(stats.isFile()).to.be.false() expect(stats.isDirectory()).to.be.false() @@ -325,7 +331,7 @@ describe('asar package', function () { const ref2 = ['file4', 'file5', path.join('dir1', 'file4')] for (let j = 0, len = ref2.length; j < len; j++) { const file = ref2[j] - const p = path.join(fixtures, 'asar', 'a.asar', file) + const p = path.join(asarDir, 'a.asar', file) expect(() => { fs.lstatSync(p) }).to.throw(/ENOENT/) @@ -335,12 +341,12 @@ describe('asar package', function () { describe('fs.lstat', function () { it('handles path with trailing slash correctly', function (done) { - const p = path.join(fixtures, 'asar', 'a.asar', 'link2', 'link2', 'file1') + const p = path.join(asarDir, 'a.asar', 'link2', 'link2', 'file1') fs.lstat(p + '/', done) }) it('returns information of root', function (done) { - const p = path.join(fixtures, 'asar', 'a.asar') + const p = path.join(asarDir, 'a.asar') fs.lstat(p, function (err, stats) { expect(err).to.be.null() expect(stats.isFile()).to.be.false() @@ -352,7 +358,7 @@ describe('asar package', function () { }) it('returns information of root with stats as bigint', function (done) { - const p = path.join(fixtures, 'asar', 'a.asar') + const p = path.join(asarDir, 'a.asar') fs.lstat(p, { bigint: false }, function (err, stats) { expect(err).to.be.null() expect(stats.isFile()).to.be.false() @@ -364,7 +370,7 @@ describe('asar package', function () { }) it('returns information of a normal file', function (done) { - const p = path.join(fixtures, 'asar', 'a.asar', 'link2', 'file1') + const p = path.join(asarDir, 'a.asar', 'link2', 'file1') fs.lstat(p, function (err, stats) { expect(err).to.be.null() expect(stats.isFile()).to.be.true() @@ -376,7 +382,7 @@ describe('asar package', function () { }) it('returns information of a normal directory', function (done) { - const p = path.join(fixtures, 'asar', 'a.asar', 'dir1') + const p = path.join(asarDir, 'a.asar', 'dir1') fs.lstat(p, function (err, stats) { expect(err).to.be.null() expect(stats.isFile()).to.be.false() @@ -388,7 +394,7 @@ describe('asar package', function () { }) it('returns information of a linked file', function (done) { - const p = path.join(fixtures, 'asar', 'a.asar', 'link2', 'link1') + const p = path.join(asarDir, 'a.asar', 'link2', 'link1') fs.lstat(p, function (err, stats) { expect(err).to.be.null() expect(stats.isFile()).to.be.false() @@ -400,7 +406,7 @@ describe('asar package', function () { }) it('returns information of a linked directory', function (done) { - const p = path.join(fixtures, 'asar', 'a.asar', 'link2', 'link2') + const p = path.join(asarDir, 'a.asar', 'link2', 'link2') fs.lstat(p, function (err, stats) { expect(err).to.be.null() expect(stats.isFile()).to.be.false() @@ -412,7 +418,7 @@ describe('asar package', function () { }) it('throws ENOENT error when can not find file', function (done) { - const p = path.join(fixtures, 'asar', 'a.asar', 'file4') + const p = path.join(asarDir, 'a.asar', 'file4') fs.lstat(p, function (err) { expect(err.code).to.equal('ENOENT') done() @@ -422,12 +428,12 @@ describe('asar package', function () { describe('fs.promises.lstat', function () { it('handles path with trailing slash correctly', async function () { - const p = path.join(fixtures, 'asar', 'a.asar', 'link2', 'link2', 'file1') + const p = path.join(asarDir, 'a.asar', 'link2', 'link2', 'file1') await fs.promises.lstat(p + '/') }) it('returns information of root', async function () { - const p = path.join(fixtures, 'asar', 'a.asar') + const p = path.join(asarDir, 'a.asar') const stats = await fs.promises.lstat(p) expect(stats.isFile()).to.be.false() expect(stats.isDirectory()).to.be.true() @@ -436,7 +442,7 @@ describe('asar package', function () { }) it('returns information of root with stats as bigint', async function () { - const p = path.join(fixtures, 'asar', 'a.asar') + const p = path.join(asarDir, 'a.asar') const stats = await fs.promises.lstat(p, { bigint: false }) expect(stats.isFile()).to.be.false() expect(stats.isDirectory()).to.be.true() @@ -445,7 +451,7 @@ describe('asar package', function () { }) it('returns information of a normal file', async function () { - const p = path.join(fixtures, 'asar', 'a.asar', 'link2', 'file1') + const p = path.join(asarDir, 'a.asar', 'link2', 'file1') const stats = await fs.promises.lstat(p) expect(stats.isFile()).to.be.true() expect(stats.isDirectory()).to.be.false() @@ -454,7 +460,7 @@ describe('asar package', function () { }) it('returns information of a normal directory', async function () { - const p = path.join(fixtures, 'asar', 'a.asar', 'dir1') + const p = path.join(asarDir, 'a.asar', 'dir1') const stats = await fs.promises.lstat(p) expect(stats.isFile()).to.be.false() expect(stats.isDirectory()).to.be.true() @@ -463,7 +469,7 @@ describe('asar package', function () { }) it('returns information of a linked file', async function () { - const p = path.join(fixtures, 'asar', 'a.asar', 'link2', 'link1') + const p = path.join(asarDir, 'a.asar', 'link2', 'link1') const stats = await fs.promises.lstat(p) expect(stats.isFile()).to.be.false() expect(stats.isDirectory()).to.be.false() @@ -472,7 +478,7 @@ describe('asar package', function () { }) it('returns information of a linked directory', async function () { - const p = path.join(fixtures, 'asar', 'a.asar', 'link2', 'link2') + const p = path.join(asarDir, 'a.asar', 'link2', 'link2') const stats = await fs.promises.lstat(p) expect(stats.isFile()).to.be.false() expect(stats.isDirectory()).to.be.false() @@ -481,56 +487,56 @@ describe('asar package', function () { }) it('throws ENOENT error when can not find file', async function () { - const p = path.join(fixtures, 'asar', 'a.asar', 'file4') + const p = path.join(asarDir, 'a.asar', 'file4') await expectToThrowErrorWithCode(() => fs.promises.lstat(p), 'ENOENT') }) }) describe('fs.realpathSync', () => { it('returns real path root', () => { - const parent = fs.realpathSync(path.join(fixtures, 'asar')) + const parent = fs.realpathSync(asarDir) const p = 'a.asar' const r = fs.realpathSync(path.join(parent, p)) expect(r).to.equal(path.join(parent, p)) }) it('returns real path of a normal file', () => { - const parent = fs.realpathSync(path.join(fixtures, 'asar')) + const parent = fs.realpathSync(asarDir) const p = path.join('a.asar', 'file1') const r = fs.realpathSync(path.join(parent, p)) expect(r).to.equal(path.join(parent, p)) }) it('returns real path of a normal directory', () => { - const parent = fs.realpathSync(path.join(fixtures, 'asar')) + const parent = fs.realpathSync(asarDir) const p = path.join('a.asar', 'dir1') const r = fs.realpathSync(path.join(parent, p)) expect(r).to.equal(path.join(parent, p)) }) it('returns real path of a linked file', () => { - const parent = fs.realpathSync(path.join(fixtures, 'asar')) + const parent = fs.realpathSync(asarDir) const p = path.join('a.asar', 'link2', 'link1') const r = fs.realpathSync(path.join(parent, p)) expect(r).to.equal(path.join(parent, 'a.asar', 'file1')) }) it('returns real path of a linked directory', () => { - const parent = fs.realpathSync(path.join(fixtures, 'asar')) + const parent = fs.realpathSync(asarDir) const p = path.join('a.asar', 'link2', 'link2') const r = fs.realpathSync(path.join(parent, p)) expect(r).to.equal(path.join(parent, 'a.asar', 'dir1')) }) it('returns real path of an unpacked file', () => { - const parent = fs.realpathSync(path.join(fixtures, 'asar')) + const parent = fs.realpathSync(asarDir) const p = path.join('unpack.asar', 'a.txt') const r = fs.realpathSync(path.join(parent, p)) expect(r).to.equal(path.join(parent, p)) }) it('throws ENOENT error when can not find file', () => { - const parent = fs.realpathSync(path.join(fixtures, 'asar')) + const parent = fs.realpathSync(asarDir) const p = path.join('a.asar', 'not-exist') expect(() => { fs.realpathSync(path.join(parent, p)) @@ -540,49 +546,49 @@ describe('asar package', function () { describe('fs.realpathSync.native', () => { it('returns real path root', () => { - const parent = fs.realpathSync.native(path.join(fixtures, 'asar')) + const parent = fs.realpathSync.native(asarDir) const p = 'a.asar' const r = fs.realpathSync.native(path.join(parent, p)) expect(r).to.equal(path.join(parent, p)) }) it('returns real path of a normal file', () => { - const parent = fs.realpathSync.native(path.join(fixtures, 'asar')) + const parent = fs.realpathSync.native(asarDir) const p = path.join('a.asar', 'file1') const r = fs.realpathSync.native(path.join(parent, p)) expect(r).to.equal(path.join(parent, p)) }) it('returns real path of a normal directory', () => { - const parent = fs.realpathSync.native(path.join(fixtures, 'asar')) + const parent = fs.realpathSync.native(asarDir) const p = path.join('a.asar', 'dir1') const r = fs.realpathSync.native(path.join(parent, p)) expect(r).to.equal(path.join(parent, p)) }) it('returns real path of a linked file', () => { - const parent = fs.realpathSync.native(path.join(fixtures, 'asar')) + const parent = fs.realpathSync.native(asarDir) const p = path.join('a.asar', 'link2', 'link1') const r = fs.realpathSync.native(path.join(parent, p)) expect(r).to.equal(path.join(parent, 'a.asar', 'file1')) }) it('returns real path of a linked directory', () => { - const parent = fs.realpathSync.native(path.join(fixtures, 'asar')) + const parent = fs.realpathSync.native(asarDir) const p = path.join('a.asar', 'link2', 'link2') const r = fs.realpathSync.native(path.join(parent, p)) expect(r).to.equal(path.join(parent, 'a.asar', 'dir1')) }) it('returns real path of an unpacked file', () => { - const parent = fs.realpathSync.native(path.join(fixtures, 'asar')) + const parent = fs.realpathSync.native(asarDir) const p = path.join('unpack.asar', 'a.txt') const r = fs.realpathSync.native(path.join(parent, p)) expect(r).to.equal(path.join(parent, p)) }) it('throws ENOENT error when can not find file', () => { - const parent = fs.realpathSync.native(path.join(fixtures, 'asar')) + const parent = fs.realpathSync.native(asarDir) const p = path.join('a.asar', 'not-exist') expect(() => { fs.realpathSync.native(path.join(parent, p)) @@ -592,7 +598,7 @@ describe('asar package', function () { describe('fs.realpath', () => { it('returns real path root', done => { - const parent = fs.realpathSync(path.join(fixtures, 'asar')) + const parent = fs.realpathSync(asarDir) const p = 'a.asar' fs.realpath(path.join(parent, p), (err, r) => { expect(err).to.be.null() @@ -602,7 +608,7 @@ describe('asar package', function () { }) it('returns real path of a normal file', done => { - const parent = fs.realpathSync(path.join(fixtures, 'asar')) + const parent = fs.realpathSync(asarDir) const p = path.join('a.asar', 'file1') fs.realpath(path.join(parent, p), (err, r) => { expect(err).to.be.null() @@ -612,7 +618,7 @@ describe('asar package', function () { }) it('returns real path of a normal directory', done => { - const parent = fs.realpathSync(path.join(fixtures, 'asar')) + const parent = fs.realpathSync(asarDir) const p = path.join('a.asar', 'dir1') fs.realpath(path.join(parent, p), (err, r) => { expect(err).to.be.null() @@ -622,7 +628,7 @@ describe('asar package', function () { }) it('returns real path of a linked file', done => { - const parent = fs.realpathSync(path.join(fixtures, 'asar')) + const parent = fs.realpathSync(asarDir) const p = path.join('a.asar', 'link2', 'link1') fs.realpath(path.join(parent, p), (err, r) => { expect(err).to.be.null() @@ -632,7 +638,7 @@ describe('asar package', function () { }) it('returns real path of a linked directory', done => { - const parent = fs.realpathSync(path.join(fixtures, 'asar')) + const parent = fs.realpathSync(asarDir) const p = path.join('a.asar', 'link2', 'link2') fs.realpath(path.join(parent, p), (err, r) => { expect(err).to.be.null() @@ -642,7 +648,7 @@ describe('asar package', function () { }) it('returns real path of an unpacked file', done => { - const parent = fs.realpathSync(path.join(fixtures, 'asar')) + const parent = fs.realpathSync(asarDir) const p = path.join('unpack.asar', 'a.txt') fs.realpath(path.join(parent, p), (err, r) => { expect(err).to.be.null() @@ -652,7 +658,7 @@ describe('asar package', function () { }) it('throws ENOENT error when can not find file', done => { - const parent = fs.realpathSync(path.join(fixtures, 'asar')) + const parent = fs.realpathSync(asarDir) const p = path.join('a.asar', 'not-exist') fs.realpath(path.join(parent, p), err => { expect(err.code).to.equal('ENOENT') @@ -663,49 +669,49 @@ describe('asar package', function () { describe('fs.promises.realpath', () => { it('returns real path root', async () => { - const parent = fs.realpathSync(path.join(fixtures, 'asar')) + const parent = fs.realpathSync(asarDir) const p = 'a.asar' const r = await fs.promises.realpath(path.join(parent, p)) expect(r).to.equal(path.join(parent, p)) }) it('returns real path of a normal file', async () => { - const parent = fs.realpathSync(path.join(fixtures, 'asar')) + const parent = fs.realpathSync(asarDir) const p = path.join('a.asar', 'file1') const r = await fs.promises.realpath(path.join(parent, p)) expect(r).to.equal(path.join(parent, p)) }) it('returns real path of a normal directory', async () => { - const parent = fs.realpathSync(path.join(fixtures, 'asar')) + const parent = fs.realpathSync(asarDir) const p = path.join('a.asar', 'dir1') const r = await fs.promises.realpath(path.join(parent, p)) expect(r).to.equal(path.join(parent, p)) }) it('returns real path of a linked file', async () => { - const parent = fs.realpathSync(path.join(fixtures, 'asar')) + const parent = fs.realpathSync(asarDir) const p = path.join('a.asar', 'link2', 'link1') const r = await fs.promises.realpath(path.join(parent, p)) expect(r).to.equal(path.join(parent, 'a.asar', 'file1')) }) it('returns real path of a linked directory', async () => { - const parent = fs.realpathSync(path.join(fixtures, 'asar')) + const parent = fs.realpathSync(asarDir) const p = path.join('a.asar', 'link2', 'link2') const r = await fs.promises.realpath(path.join(parent, p)) expect(r).to.equal(path.join(parent, 'a.asar', 'dir1')) }) it('returns real path of an unpacked file', async () => { - const parent = fs.realpathSync(path.join(fixtures, 'asar')) + const parent = fs.realpathSync(asarDir) const p = path.join('unpack.asar', 'a.txt') const r = await fs.promises.realpath(path.join(parent, p)) expect(r).to.equal(path.join(parent, p)) }) it('throws ENOENT error when can not find file', async () => { - const parent = fs.realpathSync(path.join(fixtures, 'asar')) + const parent = fs.realpathSync(asarDir) const p = path.join('a.asar', 'not-exist') await expectToThrowErrorWithCode(() => fs.promises.realpath(path.join(parent, p)), 'ENOENT') }) @@ -713,7 +719,7 @@ describe('asar package', function () { describe('fs.realpath.native', () => { it('returns real path root', done => { - const parent = fs.realpathSync.native(path.join(fixtures, 'asar')) + const parent = fs.realpathSync.native(asarDir) const p = 'a.asar' fs.realpath.native(path.join(parent, p), (err, r) => { expect(err).to.be.null() @@ -723,7 +729,7 @@ describe('asar package', function () { }) it('returns real path of a normal file', done => { - const parent = fs.realpathSync.native(path.join(fixtures, 'asar')) + const parent = fs.realpathSync.native(asarDir) const p = path.join('a.asar', 'file1') fs.realpath.native(path.join(parent, p), (err, r) => { expect(err).to.be.null() @@ -733,7 +739,7 @@ describe('asar package', function () { }) it('returns real path of a normal directory', done => { - const parent = fs.realpathSync.native(path.join(fixtures, 'asar')) + const parent = fs.realpathSync.native(asarDir) const p = path.join('a.asar', 'dir1') fs.realpath.native(path.join(parent, p), (err, r) => { expect(err).to.be.null() @@ -743,7 +749,7 @@ describe('asar package', function () { }) it('returns real path of a linked file', done => { - const parent = fs.realpathSync.native(path.join(fixtures, 'asar')) + const parent = fs.realpathSync.native(asarDir) const p = path.join('a.asar', 'link2', 'link1') fs.realpath.native(path.join(parent, p), (err, r) => { expect(err).to.be.null() @@ -753,7 +759,7 @@ describe('asar package', function () { }) it('returns real path of a linked directory', done => { - const parent = fs.realpathSync.native(path.join(fixtures, 'asar')) + const parent = fs.realpathSync.native(asarDir) const p = path.join('a.asar', 'link2', 'link2') fs.realpath.native(path.join(parent, p), (err, r) => { expect(err).to.be.null() @@ -763,7 +769,7 @@ describe('asar package', function () { }) it('returns real path of an unpacked file', done => { - const parent = fs.realpathSync.native(path.join(fixtures, 'asar')) + const parent = fs.realpathSync.native(asarDir) const p = path.join('unpack.asar', 'a.txt') fs.realpath.native(path.join(parent, p), (err, r) => { expect(err).to.be.null() @@ -773,7 +779,7 @@ describe('asar package', function () { }) it('throws ENOENT error when can not find file', done => { - const parent = fs.realpathSync.native(path.join(fixtures, 'asar')) + const parent = fs.realpathSync.native(asarDir) const p = path.join('a.asar', 'not-exist') fs.realpath.native(path.join(parent, p), err => { expect(err.code).to.equal('ENOENT') @@ -784,25 +790,25 @@ describe('asar package', function () { describe('fs.readdirSync', function () { it('reads dirs from root', function () { - const p = path.join(fixtures, 'asar', 'a.asar') + const p = path.join(asarDir, 'a.asar') const dirs = fs.readdirSync(p) expect(dirs).to.deep.equal(['dir1', 'dir2', 'dir3', 'file1', 'file2', 'file3', 'link1', 'link2', 'ping.js']) }) it('reads dirs from a normal dir', function () { - const p = path.join(fixtures, 'asar', 'a.asar', 'dir1') + const p = path.join(asarDir, 'a.asar', 'dir1') const dirs = fs.readdirSync(p) expect(dirs).to.deep.equal(['file1', 'file2', 'file3', 'link1', 'link2']) }) it('reads dirs from a linked dir', function () { - const p = path.join(fixtures, 'asar', 'a.asar', 'link2', 'link2') + const p = path.join(asarDir, 'a.asar', 'link2', 'link2') const dirs = fs.readdirSync(p) expect(dirs).to.deep.equal(['file1', 'file2', 'file3', 'link1', 'link2']) }) it('throws ENOENT error when can not find file', function () { - const p = path.join(fixtures, 'asar', 'a.asar', 'not-exist') + const p = path.join(asarDir, 'a.asar', 'not-exist') expect(() => { fs.readdirSync(p) }).to.throw(/ENOENT/) @@ -811,7 +817,7 @@ describe('asar package', function () { describe('fs.readdir', function () { it('reads dirs from root', function (done) { - const p = path.join(fixtures, 'asar', 'a.asar') + const p = path.join(asarDir, 'a.asar') fs.readdir(p, function (err, dirs) { expect(err).to.be.null() expect(dirs).to.deep.equal(['dir1', 'dir2', 'dir3', 'file1', 'file2', 'file3', 'link1', 'link2', 'ping.js']) @@ -820,7 +826,7 @@ describe('asar package', function () { }) it('reads dirs from a normal dir', function (done) { - const p = path.join(fixtures, 'asar', 'a.asar', 'dir1') + const p = path.join(asarDir, 'a.asar', 'dir1') fs.readdir(p, function (err, dirs) { expect(err).to.be.null() expect(dirs).to.deep.equal(['file1', 'file2', 'file3', 'link1', 'link2']) @@ -828,7 +834,7 @@ describe('asar package', function () { }) }) it('reads dirs from a linked dir', function (done) { - const p = path.join(fixtures, 'asar', 'a.asar', 'link2', 'link2') + const p = path.join(asarDir, 'a.asar', 'link2', 'link2') fs.readdir(p, function (err, dirs) { expect(err).to.be.null() expect(dirs).to.deep.equal(['file1', 'file2', 'file3', 'link1', 'link2']) @@ -837,7 +843,7 @@ describe('asar package', function () { }) it('throws ENOENT error when can not find file', function (done) { - const p = path.join(fixtures, 'asar', 'a.asar', 'not-exist') + const p = path.join(asarDir, 'a.asar', 'not-exist') fs.readdir(p, function (err) { expect(err.code).to.equal('ENOENT') done() @@ -847,25 +853,25 @@ describe('asar package', function () { describe('fs.promises.readdir', function () { it('reads dirs from root', async function () { - const p = path.join(fixtures, 'asar', 'a.asar') + const p = path.join(asarDir, 'a.asar') const dirs = await fs.promises.readdir(p) expect(dirs).to.deep.equal(['dir1', 'dir2', 'dir3', 'file1', 'file2', 'file3', 'link1', 'link2', 'ping.js']) }) it('reads dirs from a normal dir', async function () { - const p = path.join(fixtures, 'asar', 'a.asar', 'dir1') + const p = path.join(asarDir, 'a.asar', 'dir1') const dirs = await fs.promises.readdir(p) expect(dirs).to.deep.equal(['file1', 'file2', 'file3', 'link1', 'link2']) }) it('reads dirs from a linked dir', async function () { - const p = path.join(fixtures, 'asar', 'a.asar', 'link2', 'link2') + const p = path.join(asarDir, 'a.asar', 'link2', 'link2') const dirs = await fs.promises.readdir(p) expect(dirs).to.deep.equal(['file1', 'file2', 'file3', 'link1', 'link2']) }) it('throws ENOENT error when can not find file', async function () { - const p = path.join(fixtures, 'asar', 'a.asar', 'not-exist') + const p = path.join(asarDir, 'a.asar', 'not-exist') await expectToThrowErrorWithCode(() => fs.promises.readdir(p), 'ENOENT') }) }) @@ -875,7 +881,7 @@ describe('asar package', function () { const ref2 = ['file1', 'link1', path.join('link2', 'file1')] for (let j = 0, len = ref2.length; j < len; j++) { const file = ref2[j] - const p = path.join(fixtures, 'asar', 'a.asar', file) + const p = path.join(asarDir, 'a.asar', file) const fd = fs.openSync(p, 'r') const buffer = Buffer.alloc(6) fs.readSync(fd, buffer, 0, 6, 0) @@ -885,7 +891,7 @@ describe('asar package', function () { }) it('throws ENOENT error when can not find file', function () { - const p = path.join(fixtures, 'asar', 'a.asar', 'not-exist') + const p = path.join(asarDir, 'a.asar', 'not-exist') expect(() => { fs.openSync(p) }).to.throw(/ENOENT/) @@ -894,7 +900,7 @@ describe('asar package', function () { describe('fs.open', function () { it('opens a normal file', function (done) { - const p = path.join(fixtures, 'asar', 'a.asar', 'file1') + const p = path.join(asarDir, 'a.asar', 'file1') fs.open(p, 'r', function (err, fd) { expect(err).to.be.null() const buffer = Buffer.alloc(6) @@ -907,7 +913,7 @@ describe('asar package', function () { }) it('throws ENOENT error when can not find file', function (done) { - const p = path.join(fixtures, 'asar', 'a.asar', 'not-exist') + const p = path.join(asarDir, 'a.asar', 'not-exist') fs.open(p, 'r', function (err) { expect(err.code).to.equal('ENOENT') done() @@ -917,7 +923,7 @@ describe('asar package', function () { describe('fs.promises.open', function () { it('opens a normal file', async function () { - const p = path.join(fixtures, 'asar', 'a.asar', 'file1') + const p = path.join(asarDir, 'a.asar', 'file1') const fh = await fs.promises.open(p, 'r') const buffer = Buffer.alloc(6) await fh.read(buffer, 0, 6, 0) @@ -926,14 +932,14 @@ describe('asar package', function () { }) it('throws ENOENT error when can not find file', async function () { - const p = path.join(fixtures, 'asar', 'a.asar', 'not-exist') + const p = path.join(asarDir, 'a.asar', 'not-exist') await expectToThrowErrorWithCode(() => fs.promises.open(p, 'r'), 'ENOENT') }) }) describe('fs.mkdir', function () { it('throws error when calling inside asar archive', function (done) { - const p = path.join(fixtures, 'asar', 'a.asar', 'not-exist') + const p = path.join(asarDir, 'a.asar', 'not-exist') fs.mkdir(p, function (err) { expect(err.code).to.equal('ENOTDIR') done() @@ -943,14 +949,14 @@ describe('asar package', function () { describe('fs.promises.mkdir', function () { it('throws error when calling inside asar archive', async function () { - const p = path.join(fixtures, 'asar', 'a.asar', 'not-exist') + const p = path.join(asarDir, 'a.asar', 'not-exist') await expectToThrowErrorWithCode(() => fs.promises.mkdir(p), 'ENOTDIR') }) }) describe('fs.mkdirSync', function () { it('throws error when calling inside asar archive', function () { - const p = path.join(fixtures, 'asar', 'a.asar', 'not-exist') + const p = path.join(asarDir, 'a.asar', 'not-exist') expect(() => { fs.mkdirSync(p) }).to.throw(/ENOTDIR/) @@ -959,7 +965,7 @@ describe('asar package', function () { describe('fs.exists', function () { it('handles an existing file', function (done) { - const p = path.join(fixtures, 'asar', 'a.asar', 'file1') + const p = path.join(asarDir, 'a.asar', 'file1') // eslint-disable-next-line fs.exists(p, function (exists) { expect(exists).to.be.true() @@ -968,7 +974,7 @@ describe('asar package', function () { }) it('handles a non-existent file', function (done) { - const p = path.join(fixtures, 'asar', 'a.asar', 'not-exist') + const p = path.join(asarDir, 'a.asar', 'not-exist') // eslint-disable-next-line fs.exists(p, function (exists) { expect(exists).to.be.false() @@ -977,7 +983,7 @@ describe('asar package', function () { }) it('promisified version handles an existing file', (done) => { - const p = path.join(fixtures, 'asar', 'a.asar', 'file1') + const p = path.join(asarDir, 'a.asar', 'file1') // eslint-disable-next-line util.promisify(fs.exists)(p).then(exists => { expect(exists).to.be.true() @@ -986,7 +992,7 @@ describe('asar package', function () { }) it('promisified version handles a non-existent file', function (done) { - const p = path.join(fixtures, 'asar', 'a.asar', 'not-exist') + const p = path.join(asarDir, 'a.asar', 'not-exist') // eslint-disable-next-line util.promisify(fs.exists)(p).then(exists => { expect(exists).to.be.false() @@ -997,19 +1003,19 @@ describe('asar package', function () { describe('fs.existsSync', function () { it('handles an existing file', function () { - const p = path.join(fixtures, 'asar', 'a.asar', 'file1') + const p = path.join(asarDir, 'a.asar', 'file1') expect(fs.existsSync(p)).to.be.true() }) it('handles a non-existent file', function () { - const p = path.join(fixtures, 'asar', 'a.asar', 'not-exist') + const p = path.join(asarDir, 'a.asar', 'not-exist') expect(fs.existsSync(p)).to.be.false() }) }) describe('fs.access', function () { it('accesses a normal file', function (done) { - const p = path.join(fixtures, 'asar', 'a.asar', 'file1') + const p = path.join(asarDir, 'a.asar', 'file1') fs.access(p, function (err) { expect(err).to.be.undefined() done() @@ -1017,7 +1023,7 @@ describe('asar package', function () { }) it('throws an error when called with write mode', function (done) { - const p = path.join(fixtures, 'asar', 'a.asar', 'file1') + const p = path.join(asarDir, 'a.asar', 'file1') fs.access(p, fs.constants.R_OK | fs.constants.W_OK, function (err) { expect(err.code).to.equal('EACCES') done() @@ -1025,7 +1031,7 @@ describe('asar package', function () { }) it('throws an error when called on non-existent file', function (done) { - const p = path.join(fixtures, 'asar', 'a.asar', 'not-exist') + const p = path.join(asarDir, 'a.asar', 'not-exist') fs.access(p, function (err) { expect(err.code).to.equal('ENOENT') done() @@ -1033,7 +1039,7 @@ describe('asar package', function () { }) it('allows write mode for unpacked files', function (done) { - const p = path.join(fixtures, 'asar', 'unpack.asar', 'a.txt') + const p = path.join(asarDir, 'unpack.asar', 'a.txt') fs.access(p, fs.constants.R_OK | fs.constants.W_OK, function (err) { expect(err).to.be.null() done() @@ -1043,50 +1049,50 @@ describe('asar package', function () { describe('fs.promises.access', function () { it('accesses a normal file', async function () { - const p = path.join(fixtures, 'asar', 'a.asar', 'file1') + const p = path.join(asarDir, 'a.asar', 'file1') await fs.promises.access(p) }) it('throws an error when called with write mode', async function () { - const p = path.join(fixtures, 'asar', 'a.asar', 'file1') + const p = path.join(asarDir, 'a.asar', 'file1') await expectToThrowErrorWithCode(() => fs.promises.access(p, fs.constants.R_OK | fs.constants.W_OK), 'EACCES') }) it('throws an error when called on non-existent file', async function () { - const p = path.join(fixtures, 'asar', 'a.asar', 'not-exist') + const p = path.join(asarDir, 'a.asar', 'not-exist') await expectToThrowErrorWithCode(() => fs.promises.access(p), 'ENOENT') }) it('allows write mode for unpacked files', async function () { - const p = path.join(fixtures, 'asar', 'unpack.asar', 'a.txt') + const p = path.join(asarDir, 'unpack.asar', 'a.txt') await fs.promises.access(p, fs.constants.R_OK | fs.constants.W_OK) }) }) describe('fs.accessSync', function () { it('accesses a normal file', function () { - const p = path.join(fixtures, 'asar', 'a.asar', 'file1') + const p = path.join(asarDir, 'a.asar', 'file1') expect(() => { fs.accessSync(p) }).to.not.throw() }) it('throws an error when called with write mode', function () { - const p = path.join(fixtures, 'asar', 'a.asar', 'file1') + const p = path.join(asarDir, 'a.asar', 'file1') expect(() => { fs.accessSync(p, fs.constants.R_OK | fs.constants.W_OK) }).to.throw(/EACCES/) }) it('throws an error when called on non-existent file', function () { - const p = path.join(fixtures, 'asar', 'a.asar', 'not-exist') + const p = path.join(asarDir, 'a.asar', 'not-exist') expect(() => { fs.accessSync(p) }).to.throw(/ENOENT/) }) it('allows write mode for unpacked files', function () { - const p = path.join(fixtures, 'asar', 'unpack.asar', 'a.txt') + const p = path.join(asarDir, 'unpack.asar', 'a.txt') expect(() => { fs.accessSync(p, fs.constants.R_OK | fs.constants.W_OK) }).to.not.throw() @@ -1101,7 +1107,7 @@ describe('asar package', function () { }) it('opens a normal js file', function (done) { - const child = ChildProcess.fork(path.join(fixtures, 'asar', 'a.asar', 'ping.js')) + const child = ChildProcess.fork(path.join(asarDir, 'a.asar', 'ping.js')) child.on('message', function (msg) { expect(msg).to.equal('message') done() @@ -1110,7 +1116,7 @@ describe('asar package', function () { }) it('supports asar in the forked js', function (done) { - const file = path.join(fixtures, 'asar', 'a.asar', 'file1') + const file = path.join(asarDir, 'a.asar', 'file1') const child = ChildProcess.fork(path.join(fixtures, 'module', 'asar.js')) child.on('message', function (content) { expect(content).to.equal(fs.readFileSync(file).toString()) @@ -1121,7 +1127,7 @@ describe('asar package', function () { }) describe('child_process.exec', function () { - const echo = path.join(fixtures, 'asar', 'echo.asar', 'echo') + const echo = path.join(asarDir, 'echo.asar', 'echo') it('should not try to extract the command if there is a reference to a file inside an .asar', function (done) { ChildProcess.exec('echo ' + echo + ' foo bar', function (error, stdout) { @@ -1139,7 +1145,7 @@ describe('asar package', function () { }) describe('child_process.execSync', function () { - const echo = path.join(fixtures, 'asar', 'echo.asar', 'echo') + const echo = path.join(asarDir, 'echo.asar', 'echo') it('should not try to extract the command if there is a reference to a file inside an .asar', function (done) { const stdout = ChildProcess.execSync('echo ' + echo + ' foo bar') @@ -1151,7 +1157,7 @@ describe('asar package', function () { describe('child_process.execFile', function () { const execFile = ChildProcess.execFile const execFileSync = ChildProcess.execFileSync - const echo = path.join(fixtures, 'asar', 'echo.asar', 'echo') + const echo = path.join(asarDir, 'echo.asar', 'echo') before(function () { if (process.platform !== 'darwin') { @@ -1195,16 +1201,16 @@ describe('asar package', function () { const internalModuleReadJSON = process.binding('fs').internalModuleReadJSON it('read a normal file', function () { - const file1 = path.join(fixtures, 'asar', 'a.asar', 'file1') + const file1 = path.join(asarDir, 'a.asar', 'file1') expect(internalModuleReadJSON(file1).toString().trim()).to.equal('file1') - const file2 = path.join(fixtures, 'asar', 'a.asar', 'file2') + const file2 = path.join(asarDir, 'a.asar', 'file2') expect(internalModuleReadJSON(file2).toString().trim()).to.equal('file2') - const file3 = path.join(fixtures, 'asar', 'a.asar', 'file3') + const file3 = path.join(asarDir, 'a.asar', 'file3') expect(internalModuleReadJSON(file3).toString().trim()).to.equal('file3') }) it('reads a normal file with unpacked files', function () { - const p = path.join(fixtures, 'asar', 'unpack.asar', 'a.txt') + const p = path.join(asarDir, 'unpack.asar', 'a.txt') expect(internalModuleReadJSON(p).toString().trim()).to.equal('a') }) }) @@ -1241,8 +1247,8 @@ describe('asar package', function () { }) it('disables asar support in sync API', function () { - const file = path.join(fixtures, 'asar', 'a.asar', 'file1') - const dir = path.join(fixtures, 'asar', 'a.asar', 'dir1') + const file = path.join(asarDir, 'a.asar', 'file1') + const dir = path.join(asarDir, 'a.asar', 'dir1') expect(() => { fs.readFileSync(file) }).to.throw(new RegExp(errorName)) @@ -1258,8 +1264,8 @@ describe('asar package', function () { }) it('disables asar support in async API', function (done) { - const file = path.join(fixtures, 'asar', 'a.asar', 'file1') - const dir = path.join(fixtures, 'asar', 'a.asar', 'dir1') + const file = path.join(asarDir, 'a.asar', 'file1') + const dir = path.join(asarDir, 'a.asar', 'dir1') fs.readFile(file, function (error) { expect(error.code).to.equal(errorName) fs.lstat(file, function (error) { @@ -1276,8 +1282,8 @@ describe('asar package', function () { }) it('disables asar support in promises API', async function () { - const file = path.join(fixtures, 'asar', 'a.asar', 'file1') - const dir = path.join(fixtures, 'asar', 'a.asar', 'dir1') + const file = path.join(asarDir, 'a.asar', 'file1') + const dir = path.join(asarDir, 'a.asar', 'dir1') await expect(fs.promises.readFile(file)).to.be.eventually.rejectedWith(Error, new RegExp(errorName)) await expect(fs.promises.lstat(file)).to.be.eventually.rejectedWith(Error, new RegExp(errorName)) await expect(fs.promises.realpath(file)).to.be.eventually.rejectedWith(Error, new RegExp(errorName)) @@ -1286,7 +1292,7 @@ describe('asar package', function () { it('treats *.asar as normal file', function () { const originalFs = require('original-fs') - const asar = path.join(fixtures, 'asar', 'a.asar') + const asar = path.join(asarDir, 'a.asar') const content1 = fs.readFileSync(asar) const content2 = originalFs.readFileSync(asar) expect(content1.compare(content2)).to.equal(0) @@ -1354,7 +1360,7 @@ describe('asar package', function () { }) it('can request a file in package', function (done) { - const p = path.resolve(fixtures, 'asar', 'a.asar', 'file1') + const p = path.resolve(asarDir, 'a.asar', 'file1') $.get('file://' + p, function (data) { expect(data.trim()).to.equal('file1') done() @@ -1362,7 +1368,7 @@ describe('asar package', function () { }) it('can request a file in package with unpacked files', function (done) { - const p = path.resolve(fixtures, 'asar', 'unpack.asar', 'a.txt') + const p = path.resolve(asarDir, 'unpack.asar', 'a.txt') $.get('file://' + p, function (data) { expect(data.trim()).to.equal('a') done() @@ -1370,7 +1376,7 @@ describe('asar package', function () { }) it('can request a linked file in package', function (done) { - const p = path.resolve(fixtures, 'asar', 'a.asar', 'link2', 'link1') + const p = path.resolve(asarDir, 'a.asar', 'link2', 'link1') $.get('file://' + p, function (data) { expect(data.trim()).to.equal('file1') done() @@ -1378,7 +1384,7 @@ describe('asar package', function () { }) it('can request a file in filesystem', function (done) { - const p = path.resolve(fixtures, 'asar', 'file') + const p = path.resolve(asarDir, 'file') $.get('file://' + p, function (data) { expect(data.trim()).to.equal('file') done() @@ -1386,7 +1392,7 @@ describe('asar package', function () { }) it('gets 404 when file is not found', function (done) { - const p = path.resolve(fixtures, 'asar', 'a.asar', 'no-exist') + const p = path.resolve(asarDir, 'a.asar', 'no-exist') $.ajax({ url: 'file://' + p, error: function (err) { @@ -1409,7 +1415,7 @@ describe('asar package', function () { nodeIntegration: true } }) - const p = path.resolve(fixtures, 'asar', 'web.asar', 'index.html') + const p = path.resolve(asarDir, 'web.asar', 'index.html') ipcMain.once('dirname', function (event, dirname) { expect(dirname).to.equal(path.dirname(p)) done() @@ -1430,7 +1436,7 @@ describe('asar package', function () { nodeIntegration: true } }) - const p = path.resolve(fixtures, 'asar', 'script.asar', 'index.html') + const p = path.resolve(asarDir, 'script.asar', 'index.html') w.loadFile(p) ipcMain.once('ping', function (event, message) { expect(message).to.equal('pong') @@ -1453,7 +1459,7 @@ describe('asar package', function () { nodeIntegration: true } }) - const p = path.resolve(fixtures, 'asar', 'video.asar', 'index.html') + const p = path.resolve(asarDir, 'video.asar', 'index.html') w.loadFile(p) ipcMain.on('asar-video', function (event, message, error) { if (message === 'ended') { @@ -1470,7 +1476,7 @@ describe('asar package', function () { const originalFs = require('original-fs') it('treats .asar as file', function () { - const file = path.join(fixtures, 'asar', 'a.asar') + const file = path.join(asarDir, 'a.asar') const stats = originalFs.statSync(file) expect(stats.isFile()).to.be.true() }) @@ -1490,7 +1496,7 @@ describe('asar package', function () { }) it('can be used with streams', () => { - originalFs.createReadStream(path.join(fixtures, 'asar', 'a.asar')) + originalFs.createReadStream(path.join(asarDir, 'a.asar')) }) it('has the same APIs as fs', function () { @@ -1503,7 +1509,7 @@ describe('asar package', function () { const gfs = require('graceful-fs') it('recognize asar archvies', function () { - const p = path.join(fixtures, 'asar', 'a.asar', 'link1') + const p = path.join(asarDir, 'a.asar', 'link1') expect(gfs.readFileSync(p).toString().trim()).to.equal('file1') }) it('does not touch global fs object', function () { @@ -1515,7 +1521,7 @@ describe('asar package', function () { const mkdirp = require('mkdirp') it('throws error when calling inside asar archive', function () { - const p = path.join(fixtures, 'asar', 'a.asar', 'not-exist') + const p = path.join(asarDir, 'a.asar', 'not-exist') expect(() => { mkdirp.sync(p) }).to.throw(/ENOTDIR/) @@ -1524,7 +1530,7 @@ describe('asar package', function () { describe('native-image', function () { it('reads image from asar archive', function () { - const p = path.join(fixtures, 'asar', 'logo.asar', 'logo.png') + const p = path.join(asarDir, 'logo.asar', 'logo.png') const logo = nativeImage.createFromPath(p) expect(logo.getSize()).to.deep.equal({ width: 55, @@ -1533,7 +1539,7 @@ describe('asar package', function () { }) it('reads image from asar archive with unpacked files', function () { - const p = path.join(fixtures, 'asar', 'unpack.asar', 'atom.png') + const p = path.join(asarDir, 'unpack.asar', 'atom.png') const logo = nativeImage.createFromPath(p) expect(logo.getSize()).to.deep.equal({ width: 1024, diff --git a/spec/fixtures/module/no-asar.js b/spec/fixtures/module/no-asar.js index e574e3c6511b..400a8525ffa4 100644 --- a/spec/fixtures/module/no-asar.js +++ b/spec/fixtures/module/no-asar.js @@ -1,7 +1,7 @@ const fs = require('fs') const path = require('path') -const stats = fs.statSync(path.join(__dirname, '..', 'asar', 'a.asar')) +const stats = fs.statSync(path.join(__dirname, '..', 'test.asar', 'a.asar')) const details = { isFile: stats.isFile(), diff --git a/spec/fixtures/no-proprietary-codecs.js b/spec/fixtures/no-proprietary-codecs.js index d29342d0ea2c..741927b44f27 100644 --- a/spec/fixtures/no-proprietary-codecs.js +++ b/spec/fixtures/no-proprietary-codecs.js @@ -25,7 +25,7 @@ app.once('ready', () => { app.exit(1) }) - window.loadFile(path.resolve(__dirname, 'asar', 'video.asar', 'index.html')) + window.loadFile(path.resolve(__dirname, 'test.asar', 'video.asar', 'index.html')) ipcMain.on('asar-video', (event, message, error) => { if (message === 'ended') { diff --git a/spec/fixtures/asar/a.asar b/spec/fixtures/test.asar/a.asar similarity index 100% rename from spec/fixtures/asar/a.asar rename to spec/fixtures/test.asar/a.asar diff --git a/spec/fixtures/asar/echo.asar b/spec/fixtures/test.asar/echo.asar similarity index 100% rename from spec/fixtures/asar/echo.asar rename to spec/fixtures/test.asar/echo.asar diff --git a/spec/fixtures/asar/empty.asar b/spec/fixtures/test.asar/empty.asar similarity index 100% rename from spec/fixtures/asar/empty.asar rename to spec/fixtures/test.asar/empty.asar diff --git a/spec/fixtures/asar/file b/spec/fixtures/test.asar/file similarity index 100% rename from spec/fixtures/asar/file rename to spec/fixtures/test.asar/file diff --git a/spec/fixtures/asar/logo.asar b/spec/fixtures/test.asar/logo.asar similarity index 100% rename from spec/fixtures/asar/logo.asar rename to spec/fixtures/test.asar/logo.asar diff --git a/spec/fixtures/asar/script.asar b/spec/fixtures/test.asar/script.asar similarity index 100% rename from spec/fixtures/asar/script.asar rename to spec/fixtures/test.asar/script.asar diff --git a/spec/fixtures/asar/unpack.asar b/spec/fixtures/test.asar/unpack.asar similarity index 100% rename from spec/fixtures/asar/unpack.asar rename to spec/fixtures/test.asar/unpack.asar diff --git a/spec/fixtures/asar/unpack.asar.unpacked/a.txt b/spec/fixtures/test.asar/unpack.asar.unpacked/a.txt similarity index 100% rename from spec/fixtures/asar/unpack.asar.unpacked/a.txt rename to spec/fixtures/test.asar/unpack.asar.unpacked/a.txt diff --git a/spec/fixtures/asar/unpack.asar.unpacked/atom.png b/spec/fixtures/test.asar/unpack.asar.unpacked/atom.png similarity index 100% rename from spec/fixtures/asar/unpack.asar.unpacked/atom.png rename to spec/fixtures/test.asar/unpack.asar.unpacked/atom.png diff --git a/spec/fixtures/asar/video.asar b/spec/fixtures/test.asar/video.asar similarity index 100% rename from spec/fixtures/asar/video.asar rename to spec/fixtures/test.asar/video.asar diff --git a/spec/fixtures/asar/web.asar b/spec/fixtures/test.asar/web.asar similarity index 100% rename from spec/fixtures/asar/web.asar rename to spec/fixtures/test.asar/web.asar