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

Method checkPath

daemon/src/service/system_file.ts:79–100  ·  view source on GitHub ↗
(fileNameOrPath: string)

Source from the content-addressed store, hash-verified

77 }
78
79 checkPath(fileNameOrPath: string) {
80 if (this.isRootTopRath()) return true;
81 const destAbsolutePath = path.normalize(this.toAbsolutePath(fileNameOrPath));
82 const topAbsolutePath = path.normalize(this.topPath);
83
84 const destPath = destAbsolutePath.endsWith(path.sep)
85 ? destAbsolutePath.slice(0, -1)
86 : destAbsolutePath;
87 const topPath = topAbsolutePath.endsWith(path.sep)
88 ? topAbsolutePath.slice(0, -1)
89 : topAbsolutePath;
90
91 this.assertInsideWorkspace(destPath);
92
93 if (destPath.startsWith(topPath)) {
94 const parts = destPath.split(path.sep);
95 return topPath.split(path.sep).every((part, index) => {
96 return part === parts[index];
97 });
98 }
99 return false;
100 }
101
102 assertInsideWorkspace(fileNameOrPath: string) {
103 const absPath = this.toAbsolutePath(fileNameOrPath);

Callers 15

checkMethod · 0.95
newFileMethod · 0.95
copyMethod · 0.95
mkdirMethod · 0.95
moveMethod · 0.95
unzipMethod · 0.95
zipMethod · 0.95
renameMethod · 0.95
toggleModMethod · 0.95
deleteModMethod · 0.95
installModMethod · 0.95
getModConfigMethod · 0.95

Calls 3

isRootTopRathMethod · 0.95
toAbsolutePathMethod · 0.95
assertInsideWorkspaceMethod · 0.95

Tested by

no test coverage detected