Skip to content

Commit d38a870

Browse files
committed
fs rename windows fixes
1 parent 4f2411a commit d38a870

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

src/platform.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,8 +371,27 @@ export class App {
371371

372372
if (this.opts.tmpdir !== false) {
373373
debug(`Moving ${this.stagingPath} to ${finalPath}`);
374-
await fs.promises.mkdir(finalPath, { recursive: true });
375-
await promisifiedGracefulFs.rename(this.stagingPath, finalPath);
374+
try {
375+
await fs.promises.mkdir(path.resolve(finalPath, '..'), {
376+
recursive: true,
377+
});
378+
await fs.promises.rename(this.stagingPath, finalPath);
379+
} catch (err) {
380+
if ((err as NodeJS.ErrnoException).code === 'EXDEV') {
381+
// Cross-device link, fallback to copy and delete
382+
await fs.promises.cp(this.stagingPath, finalPath, {
383+
force: true,
384+
recursive: true,
385+
verbatimSymlinks: true,
386+
});
387+
await fs.promises.rm(this.stagingPath, {
388+
force: true,
389+
recursive: true,
390+
});
391+
} else {
392+
throw err;
393+
}
394+
}
376395
}
377396

378397
if (this.opts.afterComplete) {

0 commit comments

Comments
 (0)