From 010d1dc8af02479690952abef08a0cca416787f5 Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Sun, 12 Apr 2020 14:03:56 +0300 Subject: [PATCH 1/4] don't create folder when it exists --- cli/asc.js | 3 ++- cli/util/mkdirp.js | 11 +++++------ cli/util/utf8.js | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/cli/asc.js b/cli/asc.js index 38e8eb56fb..63935c9ac6 100644 --- a/cli/asc.js +++ b/cli/asc.js @@ -1041,7 +1041,8 @@ exports.main = function main(argv, options, callback) { try { stats.writeCount++; stats.writeTime += measure(() => { - mkdirp(path.join(baseDir, path.dirname(filename))); + const dirPath = path.join(baseDir, path.dirname(filename)); + if (!fs.existsSync(dirPath)) mkdirp(dirPath); if (typeof contents === "string") { fs.writeFileSync(path.join(baseDir, filename), contents, { encoding: "utf8" } ); } else { diff --git a/cli/util/mkdirp.js b/cli/util/mkdirp.js index bc7bffa8bb..59da6513f0 100644 --- a/cli/util/mkdirp.js +++ b/cli/util/mkdirp.js @@ -2,7 +2,7 @@ * @fileoverview Recursive mkdir. * @license * Copyright 2010 James Halliday (mail@substack.net) - * + * * This project is free software released under the MIT/X11 license: * * Permission is hereby granted, free of charge, to any person obtaining a copy @@ -11,7 +11,7 @@ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * @@ -24,9 +24,8 @@ * THE SOFTWARE. */ -var path = require("path"); -var fs = require("fs"); -var _0777 = parseInt("0777", 8); +const path = require("path"); +const fs = require("fs"); module.exports = function mkdirp(p, opts, made) { if (!opts || typeof opts !== "object") { @@ -34,7 +33,7 @@ module.exports = function mkdirp(p, opts, made) { } var mode = opts.mode; if (mode === undefined) { - mode = _0777 & (~process.umask()); + mode = 0o777 & (~process.umask()); } if (!made) made = null; p = path.resolve(p); diff --git a/cli/util/utf8.js b/cli/util/utf8.js index 0b37c859b1..076038b10b 100644 --- a/cli/util/utf8.js +++ b/cli/util/utf8.js @@ -20,7 +20,7 @@ var utf8 = exports; utf8.length = function utf8_length(string) { var len = 0, c = 0; - for (var i = 0; i < string.length; ++i) { + for (var i = 0, l = string.length; i < l; ++i) { c = string.charCodeAt(i); if (c < 128) len += 1; From c621e1f2c61595b715d74687cffdaf6e371a7dc2 Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Sun, 12 Apr 2020 18:36:54 +0300 Subject: [PATCH 2/4] use resolve instead join --- cli/asc.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/asc.js b/cli/asc.js index 63935c9ac6..3823624f85 100644 --- a/cli/asc.js +++ b/cli/asc.js @@ -1041,7 +1041,7 @@ exports.main = function main(argv, options, callback) { try { stats.writeCount++; stats.writeTime += measure(() => { - const dirPath = path.join(baseDir, path.dirname(filename)); + const dirPath = path.resolve(baseDir, path.dirname(filename)); if (!fs.existsSync(dirPath)) mkdirp(dirPath); if (typeof contents === "string") { fs.writeFileSync(path.join(baseDir, filename), contents, { encoding: "utf8" } ); From 183163cbd61fa5cebf32bc5f5c63a364b0d0beee Mon Sep 17 00:00:00 2001 From: Surma Date: Sun, 12 Apr 2020 18:06:01 +0100 Subject: [PATCH 3/4] Respect absolute output paths --- cli/asc.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cli/asc.js b/cli/asc.js index 3823624f85..8a38d2d3ba 100644 --- a/cli/asc.js +++ b/cli/asc.js @@ -1042,11 +1042,13 @@ exports.main = function main(argv, options, callback) { stats.writeCount++; stats.writeTime += measure(() => { const dirPath = path.resolve(baseDir, path.dirname(filename)); + filename = path.basename(filename); + const outputFilePath = path.join(dirPath, filename); if (!fs.existsSync(dirPath)) mkdirp(dirPath); if (typeof contents === "string") { - fs.writeFileSync(path.join(baseDir, filename), contents, { encoding: "utf8" } ); + fs.writeFileSync(outputFilePath, contents, { encoding: "utf8" } ); } else { - fs.writeFileSync(path.join(baseDir, filename), contents); + fs.writeFileSync(outputFilePath, contents); } }); return true; From 03a0651a1757528e8371c5a1f0e188765b93b463 Mon Sep 17 00:00:00 2001 From: Surma Date: Sun, 12 Apr 2020 18:22:09 +0100 Subject: [PATCH 4/4] Add myself to NOTICE file --- NOTICE | 1 + 1 file changed, 1 insertion(+) diff --git a/NOTICE b/NOTICE index 3cbcecc156..312b59d128 100644 --- a/NOTICE +++ b/NOTICE @@ -20,6 +20,7 @@ under the licensing terms detailed in LICENSE: * Jeffrey Charles * Vladimir Tikhonov * Duncan Uszkay +* Surma Portions of this software are derived from third-party works licensed under the following terms: