Files
meteor/tools/cli/dev-bundle-links.js
Ben Newman 1dac34f00c Store .meteor/dev_bundle target as text when symbolic linking fails.
This wouldn't work if .meteor/dev_bundle needed to be a true symbolic
link, but fortunately we just need to record the target path in a way that
allows us to read it later.

Fixes #7374.
2016-07-09 17:15:21 -04:00

28 lines
563 B
JavaScript

var fs = require("fs");
exports.makeLink = function (target, linkPath) {
var tempPath = linkPath + "-" + Math.random().toString(36).slice(2);
try {
fs.symlinkSync(target, tempPath, "junction");
} catch (e) {
fs.writeFileSync(tempPath, target, "utf8");
}
fs.renameSync(tempPath, linkPath);
};
exports.readLink = function (linkPath) {
var stat = fs.lstatSync(linkPath);
if (stat.isSymbolicLink()) {
return fs.realpathSync(linkPath);
}
if (stat.isFile()) {
return fs.readFileSync(linkPath, "utf8");
}
return linkPath;
};