From 1892633dbae0fe173eede33d79b42817e28878a2 Mon Sep 17 00:00:00 2001 From: Ben Newman Date: Thu, 10 May 2018 14:24:39 -0400 Subject: [PATCH] Avoid unnecessary files.{rm_recursive,symlink} in symlinkWithOverwrite. When we copy node_modules directories during rebuilds, we try to create symlinks instead of doing a full recursive copy. Very often, however, the symlinks already exist, and they point to the right location already, so we can avoid recreating them for even better performance. Another optimization identified by using the qualia:profile package created by @veered: https://atmospherejs.com/qualia/profile --- tools/fs/files.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tools/fs/files.js b/tools/fs/files.js index e425061130..7c5a41e216 100644 --- a/tools/fs/files.js +++ b/tools/fs/files.js @@ -533,6 +533,11 @@ export function symlinkWithOverwrite(source, target) { files.symlink(source, target); } catch (e) { if (e.code === "EEXIST") { + if (files.readlink(target) === source) { + // If the target already points to the desired source, we don't + // need to do anything. + return; + } // overwrite existing link, file, or directory files.rm_recursive(target); files.symlink(source, target);