import { VideoFileMetadata, VideoResolution } from '@shared/models'
import { lTags } from './object-storage/shared'
import { generateHLSVideoFilename, generateWebTorrentVideoFilename } from './paths'
+import { VideoPathManager } from './video-path-manager'
async function buildNewFile (options: {
path: string
const hls = video.getHLSPlaylist()
if (!hls) return
- await video.removeStreamingPlaylistFiles(hls)
- await hls.destroy()
+ const videoFileMutexReleaser = await VideoPathManager.Instance.lockFiles(video.uuid)
- 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) {
return undefined
}
- const toDelete = files.find(f => f.id === fileToDeleteId)
- await video.removeStreamingPlaylistVideoFile(video.getHLSPlaylist(), toDelete)
- await toDelete.destroy()
+ const videoFileMutexReleaser = await VideoPathManager.Instance.lockFiles(video.uuid)
- 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
}
// ---------------------------------------------------------------------------
async function removeAllWebTorrentFiles (video: MVideoWithAllFiles) {
- for (const file of video.VideoFiles) {
- await video.removeWebTorrentFile(file)
- await file.destroy()
- }
+ const videoFileMutexReleaser = await VideoPathManager.Instance.lockFiles(video.uuid)
+
+ try {
+ for (const file of video.VideoFiles) {
+ await video.removeWebTorrentFile(file)
+ await file.destroy()
+ }
- video.VideoFiles = []
+ video.VideoFiles = []
+ } finally {
+ videoFileMutexReleaser()
+ }
return video
}
return removeAllWebTorrentFiles(video)
}
- const toDelete = files.find(f => f.id === fileToDeleteId)
- await video.removeWebTorrentFile(toDelete)
- await toDelete.destroy()
+ const videoFileMutexReleaser = await VideoPathManager.Instance.lockFiles(video.uuid)
+ try {
+ 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
}