PeerTube/server/core/helpers/fs.ts

13 lines
311 B
TypeScript
Raw Normal View History

2023-10-05 04:09:11 -05:00
import { move } from 'fs-extra/esm'
import { rename } from 'fs/promises'
export async function tryAtomicMove (src: string, destination: string) {
try {
await rename(src, destination)
} catch (err) {
if (err?.code !== 'EXDEV') throw err
return move(src, destination, { overwrite: true })
}
}