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
This commit is contained in:
Ben Newman
2018-05-10 14:24:39 -04:00
parent 8e1287054a
commit 1892633dba

View File

@@ -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);