1
0
Fork 0

Lock when removing video files

This commit is contained in:
Chocobozzz 2023-05-22 10:16:45 +02:00
parent 33b91e53d2
commit b9393464a8
No known key found for this signature in database
GPG key ID: 583A612D890159BE

View file

@ -8,6 +8,7 @@ import { ffprobePromise, getVideoStreamDimensionsInfo, getVideoStreamFPS, isAudi
import { VideoFileMetadata, VideoResolution } from '@shared/models' import { VideoFileMetadata, VideoResolution } from '@shared/models'
import { lTags } from './object-storage/shared' import { lTags } from './object-storage/shared'
import { generateHLSVideoFilename, generateWebTorrentVideoFilename } from './paths' import { generateHLSVideoFilename, generateWebTorrentVideoFilename } from './paths'
import { VideoPathManager } from './video-path-manager'
async function buildNewFile (options: { async function buildNewFile (options: {
path: string path: string
@ -44,10 +45,16 @@ async function removeHLSPlaylist (video: MVideoWithAllFiles) {
const hls = video.getHLSPlaylist() const hls = video.getHLSPlaylist()
if (!hls) return if (!hls) return
await video.removeStreamingPlaylistFiles(hls) const videoFileMutexReleaser = await VideoPathManager.Instance.lockFiles(video.uuid)
await hls.destroy()
video.VideoStreamingPlaylists = video.VideoStreamingPlaylists.filter(p => p.id !== hls.id) try {
await video.removeStreamingPlaylistFiles(hls)
await hls.destroy()
video.VideoStreamingPlaylists = video.VideoStreamingPlaylists.filter(p => p.id !== hls.id)
} finally {
videoFileMutexReleaser()
}
} }
async function removeHLSFile (video: MVideoWithAllFiles, fileToDeleteId: number) { async function removeHLSFile (video: MVideoWithAllFiles, fileToDeleteId: number) {
@ -61,11 +68,17 @@ async function removeHLSFile (video: MVideoWithAllFiles, fileToDeleteId: number)
return undefined return undefined
} }
const toDelete = files.find(f => f.id === fileToDeleteId) const videoFileMutexReleaser = await VideoPathManager.Instance.lockFiles(video.uuid)
await video.removeStreamingPlaylistVideoFile(video.getHLSPlaylist(), toDelete)
await toDelete.destroy()
hls.VideoFiles = hls.VideoFiles.filter(f => f.id !== toDelete.id) try {
const toDelete = files.find(f => f.id === fileToDeleteId)
await video.removeStreamingPlaylistVideoFile(video.getHLSPlaylist(), toDelete)
await toDelete.destroy()
hls.VideoFiles = hls.VideoFiles.filter(f => f.id !== toDelete.id)
} finally {
videoFileMutexReleaser()
}
return hls return hls
} }
@ -73,12 +86,18 @@ async function removeHLSFile (video: MVideoWithAllFiles, fileToDeleteId: number)
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
async function removeAllWebTorrentFiles (video: MVideoWithAllFiles) { async function removeAllWebTorrentFiles (video: MVideoWithAllFiles) {
for (const file of video.VideoFiles) { const videoFileMutexReleaser = await VideoPathManager.Instance.lockFiles(video.uuid)
await video.removeWebTorrentFile(file)
await file.destroy()
}
video.VideoFiles = [] try {
for (const file of video.VideoFiles) {
await video.removeWebTorrentFile(file)
await file.destroy()
}
video.VideoFiles = []
} finally {
videoFileMutexReleaser()
}
return video return video
} }
@ -90,11 +109,16 @@ async function removeWebTorrentFile (video: MVideoWithAllFiles, fileToDeleteId:
return removeAllWebTorrentFiles(video) return removeAllWebTorrentFiles(video)
} }
const toDelete = files.find(f => f.id === fileToDeleteId) const videoFileMutexReleaser = await VideoPathManager.Instance.lockFiles(video.uuid)
await video.removeWebTorrentFile(toDelete) try {
await toDelete.destroy() const toDelete = files.find(f => f.id === fileToDeleteId)
await video.removeWebTorrentFile(toDelete)
await toDelete.destroy()
video.VideoFiles = files.filter(f => f.id !== toDelete.id) video.VideoFiles = files.filter(f => f.id !== toDelete.id)
} finally {
videoFileMutexReleaser()
}
return video return video
} }