MCPcopy Create free account
hub / github.com/MCSManager/MCSManager / toAbsolutePath

Method toAbsolutePath

daemon/src/service/system_file.ts:56–77  ·  view source on GitHub ↗
(fileName: string = "")

Source from the content-addressed store, hash-verified

54 }
55
56 toAbsolutePath(fileName: string = "") {
57 const topAbsolutePath = this.topPath;
58
59 let finalPath = "";
60 if (path.normalize(fileName).indexOf(topAbsolutePath) === 0) {
61 finalPath = fileName;
62 } else if (os.platform() === "win32") {
63 const reg = new RegExp("^[A-Za-z]{1}:[\\\\/]{1}");
64 if (reg.test(this.cwd)) {
65 finalPath = path.normalize(path.join(this.cwd, fileName));
66 } else if (reg.test(fileName)) {
67 finalPath = path.normalize(fileName);
68 }
69 }
70
71 if (!finalPath) {
72 finalPath = path.normalize(path.join(this.topPath, this.cwd, fileName));
73 }
74
75 if (this.isOutsideWorkspace(finalPath)) throw new Error(ERROR_MSG_01);
76 return finalPath;
77 }
78
79 checkPath(fileNameOrPath: string) {
80 if (this.isRootTopRath()) return true;

Callers 15

checkPathMethod · 0.95
assertInsideWorkspaceMethod · 0.95
checkMethod · 0.95
listMethod · 0.95
chmodMethod · 0.95
readFileMethod · 0.95
writeFileMethod · 0.95
newFileMethod · 0.95
copyMethod · 0.95
mkdirMethod · 0.95
deleteMethod · 0.95
moveMethod · 0.95

Calls 1

isOutsideWorkspaceMethod · 0.95

Tested by

no test coverage detected