forked from meteor/meteor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdev-bundle-links.js
More file actions
37 lines (30 loc) · 949 Bytes
/
dev-bundle-links.js
File metadata and controls
37 lines (30 loc) · 949 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
var fs = require("fs");
var files = require("../fs/mini-files.js");
exports.makeLink = function (target, linkPath) {
target = files.convertToOSPath(target);
linkPath = files.convertToOSPath(linkPath);
var tempPath = linkPath + "-" + Math.random().toString(36).slice(2);
try {
fs.symlinkSync(target, tempPath, "junction");
} catch (e) {
fs.writeFileSync(tempPath, target, "utf8");
}
try {
fs.renameSync(tempPath, linkPath);
} catch (e) {
// If renaming fails, try unlinking first.
fs.unlinkSync(linkPath);
fs.renameSync(tempPath, linkPath);
}
};
// Note: this function returns an OS-specific path!
exports.readLink = function (linkPath) {
linkPath = files.convertToOSPath(linkPath);
var stat = fs.lstatSync(linkPath);
if (stat.isSymbolicLink()) {
linkPath = fs.realpathSync(linkPath);
} else if (stat.isFile()) {
linkPath = fs.readFileSync(linkPath, "utf8");
}
return linkPath;
};