[chore-245] clean "setInstallationDirectory" process

This commit is contained in:
MathieuG-P
2023-07-16 15:10:00 +02:00
parent cab6a90c78
commit 2d7b1bd8f3
4 changed files with 37 additions and 47 deletions
@@ -43,26 +43,20 @@ export class InstallationLocationService {
this.updateListeners.forEach(listener => listener());
}
public setInstallationDirectory(newDir: string): Promise<string> {
public async setInstallationDirectory(newDir: string): Promise<string> {
const oldDir = this.installationDirectory;
const newDest = path.join(newDir, this.INSTALLATION_FOLDER);
return new Promise<string>(async (resolve, reject) => {
await ensureFolderExist(oldDir);
try {
await copyDirectoryWithJunctions(oldDir, newDest, { overwrite: true });
await ensureFolderExist(oldDir);
this._installationDirectory = newDir;
this.installPathConfig.set(this.STORE_INSTALLATION_PATH_KEY, newDir);
await copyDirectoryWithJunctions(oldDir, newDest, { overwrite: true });
deleteFolder(oldDir);
this._installationDirectory = newDir;
this.installPathConfig.set(this.STORE_INSTALLATION_PATH_KEY, newDir);
return resolve(this.installationDirectory);
} catch (err) {
log.error(err);
reject(err);
}
});
deleteFolder(oldDir);
return this.installationDirectory;
}
public onInstallLocationUpdate(fn: Listener) {