Skip to content
Snippets Groups Projects
Unverified Commit ea5b0a8f authored by carsakiller's avatar carsakiller
Browse files

fix: use fspath and better regex

parent b7c5d691
Branches
Tags
No related merge requests found
......@@ -80,9 +80,8 @@ export class Addon {
/** Update this addon using git. */
public async update() {
const path = filesystem.getCorrectPath(this.uri);
return git
.submoduleUpdate([path])
.submoduleUpdate([this.uri.fsPath])
.then((message) => localLogger.debug(message));
}
......@@ -91,7 +90,7 @@ export class Addon {
*/
public checkIfEnabled(libraryPaths: string[]) {
const regex = new RegExp(
`/sumneko.lua/addonManager/addons/${this.name}`,
`[\/\\\\]+sumneko.lua[\/\\\\]+addonManager[\/\\\\]+addons[\/\\\\]+${this.name}`,
"g"
);
......@@ -138,9 +137,8 @@ export class Addon {
}
// Init submodule
const path = filesystem.getCorrectPath(this.uri);
try {
await git.submoduleInit([path]);
await git.submoduleInit([this.uri.fsPath]);
localLogger.debug("Initialized submodule");
} catch (e) {
localLogger.error(e);
......@@ -148,7 +146,7 @@ export class Addon {
}
try {
await git.submoduleUpdate([path]);
await git.submoduleUpdate([this.uri.fsPath]);
localLogger.debug("Submodule up to date");
} catch (e) {
localLogger.error(e);
......@@ -157,7 +155,6 @@ export class Addon {
// Apply addon settings
const libraryUri = vscode.Uri.joinPath(this.uri, "module", "library");
const libraryPath = filesystem.getCorrectPath(libraryUri);
const configValues = await this.getConfigurationFile();
......@@ -166,7 +163,7 @@ export class Addon {
{
action: "add",
key: LIBRARY_SETTING,
value: libraryPath,
value: filesystem.unixifyPath(libraryUri),
uri: folder.uri,
},
]);
......@@ -190,7 +187,7 @@ export class Addon {
)) ?? []) as string[];
const regex = new RegExp(
`/sumneko.lua/addonManager/addons/${this.name}`,
`[\/\\\\]+sumneko.lua[\/\\\\]+addonManager[\/\\\\]+addons[\/\\\\]+${this.name}`,
"g"
);
const index = librarySetting.findIndex((path) => regex.test(path));
......
......@@ -13,8 +13,12 @@ type ReadDirectoryOptions = {
namespace filesystem {
export function getCorrectPath(uri: vscode.Uri): string {
return platform() === "win32" ? uri.path.substring(1) : uri.fsPath;
export function unixifyPath(uri: vscode.Uri): string {
if (platform() === "win32") {
return uri.path.substring(1);
} else {
return uri.fsPath;
}
}
/** Check if a file exists
......
......@@ -16,11 +16,9 @@ export const setupGit = async (context: vscode.ExtensionContext) => {
);
await filesystem.createDirectory(storageURI);
const localRepoPath = filesystem.getCorrectPath(storageURI);
// set working directory
try {
await git.cwd({ path: localRepoPath, root: true });
await git.cwd({ path: storageURI.fsPath, root: true });
} catch (e) {
localLogger.error(e);
}
......@@ -32,10 +30,10 @@ export const setupGit = async (context: vscode.ExtensionContext) => {
const options = { "--depth": 1 };
await git.clone(
REPOSITORY_PATH,
localRepoPath,
storageURI.fsPath,
options
);
localLogger.debug(`Cloned ${REPOSITORY_NAME} to ${localRepoPath}`);
localLogger.debug(`Cloned ${REPOSITORY_NAME} to ${storageURI.fsPath}`);
} catch (e) {
localLogger.error("Failed to clone repo!");
localLogger.error(e);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment