From c9207d86856de0b96a98fe95abb5a14b341c9c70 Mon Sep 17 00:00:00 2001 From: Vladimir Agafonkin Date: Tue, 7 Feb 2017 17:43:47 +0200 Subject: [PATCH 1/2] optimize buildActionsForCopy routine --- src/util/fs.js | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/src/util/fs.js b/src/util/fs.js index 957b999fe0..5e4a311579 100644 --- a/src/util/fs.js +++ b/src/util/fs.js @@ -144,21 +144,24 @@ async function buildActionsForCopy( srcFiles = await readdir(src); } - if (await exists(dest)) { - const destStat = await lstat(dest); + let destStat; + try { + destStat = await lstat(dest); + } catch (e) {} + if (destStat) { const bothSymlinks = srcStat.isSymbolicLink() && destStat.isSymbolicLink(); const bothFolders = srcStat.isDirectory() && destStat.isDirectory(); const bothFiles = srcStat.isFile() && destStat.isFile(); - if (srcStat.mode !== destStat.mode) { - try { - await access(dest, srcStat.mode); - } catch (err) { - // EINVAL access errors sometimes happen which shouldn't because node shouldn't be giving - // us modes that aren't valid. investigate this, it's generally safe to proceed. - } - } + // EINVAL access errors sometimes happen which shouldn't because node shouldn't be giving + // us modes that aren't valid. investigate this, it's generally safe to proceed. + + // if (srcStat.mode !== destStat.mode) { + // try { + // await access(dest, srcStat.mode); + // } catch (err) {} + // } if (bothFiles && srcStat.size === destStat.size && +srcStat.mtime === +destStat.mtime) { // we can safely assume this is the same file @@ -186,12 +189,6 @@ async function buildActionsForCopy( if (srcFiles.indexOf(file) < 0) { const loc = path.join(dest, file); possibleExtraneous.add(loc); - - if ((await lstat(loc)).isDirectory()) { - for (const file of await readdir(loc)) { - possibleExtraneous.add(path.join(loc, file)); - } - } } } } @@ -207,8 +204,10 @@ async function buildActionsForCopy( }); onDone(); } else if (srcStat.isDirectory()) { - reporter.verbose(reporter.lang('verboseFileFolder', dest)); - await mkdirp(dest); + if (!destStat) { + reporter.verbose(reporter.lang('verboseFileFolder', dest)); + await mkdirp(dest); + } const destParts = dest.split(path.sep); while (destParts.length) { From d77af5037f46f0ae85991f80757ee7f5e6a5a92c Mon Sep 17 00:00:00 2001 From: Vladimir Agafonkin Date: Thu, 9 Feb 2017 14:00:31 +0200 Subject: [PATCH 2/2] more resilient sync in util.fs, add comments --- src/util/fs.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/util/fs.js b/src/util/fs.js index 5e4a311579..dce58aa78a 100644 --- a/src/util/fs.js +++ b/src/util/fs.js @@ -146,9 +146,14 @@ async function buildActionsForCopy( let destStat; try { + // try accessing the destination destStat = await lstat(dest); - } catch (e) {} + } catch (e) { + // proceed if destination doesn't exist, otherwise error + if (e.code !== 'ENOENT') throw e; + } + // if destination exists if (destStat) { const bothSymlinks = srcStat.isSymbolicLink() && destStat.isSymbolicLink(); const bothFolders = srcStat.isDirectory() && destStat.isDirectory(); @@ -157,11 +162,11 @@ async function buildActionsForCopy( // EINVAL access errors sometimes happen which shouldn't because node shouldn't be giving // us modes that aren't valid. investigate this, it's generally safe to proceed. - // if (srcStat.mode !== destStat.mode) { - // try { - // await access(dest, srcStat.mode); - // } catch (err) {} - // } + /* if (srcStat.mode !== destStat.mode) { + try { + await access(dest, srcStat.mode); + } catch (err) {} + } */ if (bothFiles && srcStat.size === destStat.size && +srcStat.mtime === +destStat.mtime) { // we can safely assume this is the same file