fix(cleaner): use copy+unlink for video rename to avoid Windows EBUSY
Windows fs.rename fails when ffmpeg still holds the file handle. Use copyFileSync + unlinkSync with retry (up to 10 attempts, 1s interval) to work around the file lock. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1294,8 +1294,24 @@ export class CleanerService {
|
||||
const finalPath = fs.existsSync(orderVideoPath)
|
||||
? path.join(this.videoDir!, `${expectedOrderNumber}_${Date.now()}${ext}`)
|
||||
: orderVideoPath
|
||||
fs.renameSync(originalPath, finalPath)
|
||||
log.debug('[视频录制] 视频已重命名', { from: originalPath, to: finalPath })
|
||||
// Copy + unlink instead of rename — Windows EBUSY if ffmpeg still holds the file
|
||||
await new Promise<void>((resolve, reject) => {
|
||||
const tryRename = (attempt: number) => {
|
||||
try {
|
||||
fs.copyFileSync(originalPath, finalPath)
|
||||
fs.unlinkSync(originalPath)
|
||||
log.debug('[视频录制] 视频已重命名', { from: originalPath, to: finalPath })
|
||||
resolve()
|
||||
} catch (err) {
|
||||
if (attempt < 10) {
|
||||
setTimeout(() => tryRename(attempt + 1), 1000)
|
||||
} else {
|
||||
reject(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
tryRename(0)
|
||||
})
|
||||
}
|
||||
} catch (videoError) {
|
||||
log.warn('[视频录制] 重命名视频失败', {
|
||||
|
||||
Reference in New Issue
Block a user