mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
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.
28 lines
563 B
JavaScript
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;
|
|
};
|