diff options
Diffstat (limited to 'editors/code/src/net.ts')
-rw-r--r-- | editors/code/src/net.ts | 9 |
1 files changed, 1 insertions, 8 deletions
diff --git a/editors/code/src/net.ts b/editors/code/src/net.ts index 3e50d352c..d39dc1baf 100644 --- a/editors/code/src/net.ts +++ b/editors/code/src/net.ts | |||
@@ -73,23 +73,16 @@ interface DownloadOpts { | |||
73 | dest: string; | 73 | dest: string; |
74 | mode?: number; | 74 | mode?: number; |
75 | gunzip?: boolean; | 75 | gunzip?: boolean; |
76 | overwrite?: boolean; | ||
77 | } | 76 | } |
78 | 77 | ||
79 | export async function download(opts: DownloadOpts) { | 78 | export async function download(opts: DownloadOpts) { |
80 | // Put artifact into a temporary file (in the same dir for simplicity) | 79 | // Put artifact into a temporary file (in the same dir for simplicity) |
81 | // to prevent partially downloaded files when user kills vscode | 80 | // to prevent partially downloaded files when user kills vscode |
81 | // This also avoids overwriting running executables | ||
82 | const dest = path.parse(opts.dest); | 82 | const dest = path.parse(opts.dest); |
83 | const randomHex = crypto.randomBytes(5).toString("hex"); | 83 | const randomHex = crypto.randomBytes(5).toString("hex"); |
84 | const tempFile = path.join(dest.dir, `${dest.name}${randomHex}`); | 84 | const tempFile = path.join(dest.dir, `${dest.name}${randomHex}`); |
85 | 85 | ||
86 | if (opts.overwrite) { | ||
87 | // Unlinking the exe file before moving new one on its place should prevent ETXTBSY error. | ||
88 | await fs.promises.unlink(opts.dest).catch(err => { | ||
89 | if (err.code !== "ENOENT") throw err; | ||
90 | }); | ||
91 | } | ||
92 | |||
93 | await vscode.window.withProgress( | 86 | await vscode.window.withProgress( |
94 | { | 87 | { |
95 | location: vscode.ProgressLocation.Notification, | 88 | location: vscode.ProgressLocation.Notification, |