Skip to content

Commit 74f1344

Browse files
committed
resolve conversations
1 parent 01263d0 commit 74f1344

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

src/main/osinstaller/CxInstaller.ts

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,10 @@ export class CxInstaller {
4444
return path.join(this.resourceDirPath, executableName);
4545
}
4646

47-
4847
public async downloadIfNotInstalledCLI(): Promise<void> {
4948
try {
50-
await fs.promises.mkdir(this.resourceDirPath, { recursive: true });
51-
49+
await fs.promises.mkdir(this.resourceDirPath, {recursive: true});
50+
5251
if (this.checkExecutableExists()) {
5352
logger.info('Executable already installed.');
5453
return;
@@ -60,15 +59,15 @@ export class CxInstaller {
6059
logger.info('Downloaded CLI to:', zipPath);
6160

6261
await this.extractArchive(zipPath, this.resourceDirPath);
63-
62+
6463
fs.unlink(zipPath, (err) => {
6564
if (err) {
66-
logger.error('Error deleting the file:', err);
65+
logger.warn('Error deleting the file:', err);
6766
} else {
6867
logger.info('File deleted successfully!');
6968
}
7069
});
71-
70+
7271
fs.chmodSync(this.getExecutablePath(), 0o755);
7372
logger.info('Extracted CLI to:', this.resourceDirPath);
7473
} catch (error) {
@@ -90,13 +89,20 @@ export class CxInstaller {
9089
private async downloadFile(url: string, outputPath: string) {
9190
logger.info('Downloading file from:', url);
9291
const writer = fs.createWriteStream(outputPath);
93-
const response = await axios({url, responseType: 'stream'});
94-
response.data.pipe(writer);
9592

96-
await finished(writer); // Use stream promises to await the writer
97-
logger.info('Download finished');
98-
}
93+
try {
94+
const response = await axios({url, responseType: 'stream'});
95+
response.data.pipe(writer);
9996

97+
await finished(writer); // Use stream promises to await the writer
98+
logger.info('Download finished');
99+
} catch (error) {
100+
logger.error('Error downloading file:', error.message || error);
101+
} finally {
102+
writer.close();
103+
}
104+
}
105+
100106
private checkExecutableExists(): boolean {
101107
return fs.existsSync(this.getExecutablePath());
102108
}
@@ -110,7 +116,7 @@ export class CxInstaller {
110116
const versionContent = await fsPromises.readFile(versionFilePath, 'utf-8');
111117
return versionContent.trim();
112118
} catch (error) {
113-
logger.error('Error reading AST CLI version: ' + error.message);
119+
logger.warn('Error reading AST CLI version: ' + error.message);
114120
return this.cliDefaultVersion;
115121
}
116122
}

0 commit comments

Comments
 (0)