495
* - attempts to retry the operation for certain error codes on Windows
496
*/
497
>
async function rename(source: string, target: string, windowsRetryTimeout: number | false = 60000): Promise<void> {
pfs.ts
498
>
if (source === target) {
499
return; // simulate node.js behaviour here and do a no-op if paths match
500
}
502
>
try {
503
>
if (isWindows && typeof windowsRetryTimeout === 'number') {
504
// On Windows, a rename can fail when either source or target
505
// is locked by AV software.
506
await renameWithRetry(source, target, Date.now(), windowsRetryTimeout);
508
>
await fs.promises.rename(source, target);
509
>
}
510
>
} catch (error) {
511
// In two cases we fallback to classic copy and delete:
512
//