Skip to content

Commit ea5b0a8

Browse files
committed
fix: use fspath and better regex
1 parent b7c5d69 commit ea5b0a8

File tree

3 files changed

+15
-16
lines changed

3 files changed

+15
-16
lines changed

client/src/addon_manager/models/addon.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,8 @@ export class Addon {
8080

8181
/** Update this addon using git. */
8282
public async update() {
83-
const path = filesystem.getCorrectPath(this.uri);
8483
return git
85-
.submoduleUpdate([path])
84+
.submoduleUpdate([this.uri.fsPath])
8685
.then((message) => localLogger.debug(message));
8786
}
8887

@@ -91,7 +90,7 @@ export class Addon {
9190
*/
9291
public checkIfEnabled(libraryPaths: string[]) {
9392
const regex = new RegExp(
94-
`/sumneko.lua/addonManager/addons/${this.name}`,
93+
`[\/\\\\]+sumneko.lua[\/\\\\]+addonManager[\/\\\\]+addons[\/\\\\]+${this.name}`,
9594
"g"
9695
);
9796

@@ -138,17 +137,16 @@ export class Addon {
138137
}
139138

140139
// Init submodule
141-
const path = filesystem.getCorrectPath(this.uri);
142140
try {
143-
await git.submoduleInit([path]);
141+
await git.submoduleInit([this.uri.fsPath]);
144142
localLogger.debug("Initialized submodule");
145143
} catch (e) {
146144
localLogger.error(e);
147145
return;
148146
}
149147

150148
try {
151-
await git.submoduleUpdate([path]);
149+
await git.submoduleUpdate([this.uri.fsPath]);
152150
localLogger.debug("Submodule up to date");
153151
} catch (e) {
154152
localLogger.error(e);
@@ -157,7 +155,6 @@ export class Addon {
157155

158156
// Apply addon settings
159157
const libraryUri = vscode.Uri.joinPath(this.uri, "module", "library");
160-
const libraryPath = filesystem.getCorrectPath(libraryUri);
161158

162159
const configValues = await this.getConfigurationFile();
163160

@@ -166,7 +163,7 @@ export class Addon {
166163
{
167164
action: "add",
168165
key: LIBRARY_SETTING,
169-
value: libraryPath,
166+
value: filesystem.unixifyPath(libraryUri),
170167
uri: folder.uri,
171168
},
172169
]);
@@ -190,7 +187,7 @@ export class Addon {
190187
)) ?? []) as string[];
191188

192189
const regex = new RegExp(
193-
`/sumneko.lua/addonManager/addons/${this.name}`,
190+
`[\/\\\\]+sumneko.lua[\/\\\\]+addonManager[\/\\\\]+addons[\/\\\\]+${this.name}`,
194191
"g"
195192
);
196193
const index = librarySetting.findIndex((path) => regex.test(path));

client/src/addon_manager/services/filesystem.service.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,12 @@ type ReadDirectoryOptions = {
1313

1414
namespace filesystem {
1515

16-
export function getCorrectPath(uri: vscode.Uri): string {
17-
return platform() === "win32" ? uri.path.substring(1) : uri.fsPath;
16+
export function unixifyPath(uri: vscode.Uri): string {
17+
if (platform() === "win32") {
18+
return uri.path.substring(1);
19+
} else {
20+
return uri.fsPath;
21+
}
1822
}
1923

2024
/** Check if a file exists

client/src/addon_manager/services/git.service.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,9 @@ export const setupGit = async (context: vscode.ExtensionContext) => {
1616
);
1717
await filesystem.createDirectory(storageURI);
1818

19-
const localRepoPath = filesystem.getCorrectPath(storageURI);
20-
2119
// set working directory
2220
try {
23-
await git.cwd({ path: localRepoPath, root: true });
21+
await git.cwd({ path: storageURI.fsPath, root: true });
2422
} catch (e) {
2523
localLogger.error(e);
2624
}
@@ -32,10 +30,10 @@ export const setupGit = async (context: vscode.ExtensionContext) => {
3230
const options = { "--depth": 1 };
3331
await git.clone(
3432
REPOSITORY_PATH,
35-
localRepoPath,
33+
storageURI.fsPath,
3634
options
3735
);
38-
localLogger.debug(`Cloned ${REPOSITORY_NAME} to ${localRepoPath}`);
36+
localLogger.debug(`Cloned ${REPOSITORY_NAME} to ${storageURI.fsPath}`);
3937
} catch (e) {
4038
localLogger.error("Failed to clone repo!");
4139
localLogger.error(e);

0 commit comments

Comments
 (0)