From 75d5a23dbc9416343701b74013071d7dc698fb9b Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 13 Oct 2023 09:59:18 +0200 Subject: [PATCH] Prevent error when removing a streaming playlist --- server/core/models/video/video.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/server/core/models/video/video.ts b/server/core/models/video/video.ts index 44d0605cc..d513a1ee3 100644 --- a/server/core/models/video/video.ts +++ b/server/core/models/video/video.ts @@ -1,4 +1,4 @@ -import { buildVideoEmbedPath, buildVideoWatchPath, pick } from '@peertube/peertube-core-utils' +import { buildVideoEmbedPath, buildVideoWatchPath, pick, wait } from '@peertube/peertube-core-utils' import { ffprobePromise, getAudioStream, getVideoStreamDimensionsInfo, getVideoStreamFPS, hasAudioStream } from '@peertube/peertube-ffmpeg' import { ResultList, @@ -1925,7 +1925,20 @@ export class VideoModel extends Model>> { ? getHLSRedundancyDirectory(this) : getHLSDirectory(this) - await remove(directoryPath) + try { + await remove(directoryPath) + } catch (err) { + // If it's a live, ffmpeg may have added another file while fs-extra is removing the directory + // So wait a little bit and retry + if (err.code === 'ENOTEMPTY') { + await wait(1000) + await remove(directoryPath) + + return + } + + throw err + } if (isRedundancy !== true) { const streamingPlaylistWithFiles = streamingPlaylist as MStreamingPlaylistFilesVideo