aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2023-05-22 10:16:45 +0200
committerChocobozzz <me@florianbigard.com>2023-05-22 11:06:04 +0200
commitb9393464a88899530b5d87e512eee814ca3ca8d8 (patch)
treec9764d66dc331c3b9cc9d2eca3cd2dd886acd031
parent33b91e53d21fba295ecf516b717fb36e91990771 (diff)
downloadPeerTube-b9393464a88899530b5d87e512eee814ca3ca8d8.tar.gz
PeerTube-b9393464a88899530b5d87e512eee814ca3ca8d8.tar.zst
PeerTube-b9393464a88899530b5d87e512eee814ca3ca8d8.zip
Lock when removing video files
-rw-r--r--server/lib/video-file.ts56
1 files changed, 40 insertions, 16 deletions
diff --git a/server/lib/video-file.ts b/server/lib/video-file.ts
index 8fcc3c253..88d48c945 100644
--- a/server/lib/video-file.ts
+++ b/server/lib/video-file.ts
@@ -8,6 +8,7 @@ import { ffprobePromise, getVideoStreamDimensionsInfo, getVideoStreamFPS, isAudi
8import { VideoFileMetadata, VideoResolution } from '@shared/models' 8import { VideoFileMetadata, VideoResolution } from '@shared/models'
9import { lTags } from './object-storage/shared' 9import { lTags } from './object-storage/shared'
10import { generateHLSVideoFilename, generateWebTorrentVideoFilename } from './paths' 10import { generateHLSVideoFilename, generateWebTorrentVideoFilename } from './paths'
11import { VideoPathManager } from './video-path-manager'
11 12
12async function buildNewFile (options: { 13async function buildNewFile (options: {
13 path: string 14 path: string
@@ -44,10 +45,16 @@ async function removeHLSPlaylist (video: MVideoWithAllFiles) {
44 const hls = video.getHLSPlaylist() 45 const hls = video.getHLSPlaylist()
45 if (!hls) return 46 if (!hls) return
46 47
47 await video.removeStreamingPlaylistFiles(hls) 48 const videoFileMutexReleaser = await VideoPathManager.Instance.lockFiles(video.uuid)
48 await hls.destroy()
49 49
50 video.VideoStreamingPlaylists = video.VideoStreamingPlaylists.filter(p => p.id !== hls.id) 50 try {
51 await video.removeStreamingPlaylistFiles(hls)
52 await hls.destroy()
53
54 video.VideoStreamingPlaylists = video.VideoStreamingPlaylists.filter(p => p.id !== hls.id)
55 } finally {
56 videoFileMutexReleaser()
57 }
51} 58}
52 59
53async function removeHLSFile (video: MVideoWithAllFiles, fileToDeleteId: number) { 60async function removeHLSFile (video: MVideoWithAllFiles, fileToDeleteId: number) {
@@ -61,11 +68,17 @@ async function removeHLSFile (video: MVideoWithAllFiles, fileToDeleteId: number)
61 return undefined 68 return undefined
62 } 69 }
63 70
64 const toDelete = files.find(f => f.id === fileToDeleteId) 71 const videoFileMutexReleaser = await VideoPathManager.Instance.lockFiles(video.uuid)
65 await video.removeStreamingPlaylistVideoFile(video.getHLSPlaylist(), toDelete)
66 await toDelete.destroy()
67 72
68 hls.VideoFiles = hls.VideoFiles.filter(f => f.id !== toDelete.id) 73 try {
74 const toDelete = files.find(f => f.id === fileToDeleteId)
75 await video.removeStreamingPlaylistVideoFile(video.getHLSPlaylist(), toDelete)
76 await toDelete.destroy()
77
78 hls.VideoFiles = hls.VideoFiles.filter(f => f.id !== toDelete.id)
79 } finally {
80 videoFileMutexReleaser()
81 }
69 82
70 return hls 83 return hls
71} 84}
@@ -73,12 +86,18 @@ async function removeHLSFile (video: MVideoWithAllFiles, fileToDeleteId: number)
73// --------------------------------------------------------------------------- 86// ---------------------------------------------------------------------------
74 87
75async function removeAllWebTorrentFiles (video: MVideoWithAllFiles) { 88async function removeAllWebTorrentFiles (video: MVideoWithAllFiles) {
76 for (const file of video.VideoFiles) { 89 const videoFileMutexReleaser = await VideoPathManager.Instance.lockFiles(video.uuid)
77 await video.removeWebTorrentFile(file) 90
78 await file.destroy() 91 try {
79 } 92 for (const file of video.VideoFiles) {
93 await video.removeWebTorrentFile(file)
94 await file.destroy()
95 }
80 96
81 video.VideoFiles = [] 97 video.VideoFiles = []
98 } finally {
99 videoFileMutexReleaser()
100 }
82 101
83 return video 102 return video
84} 103}
@@ -90,11 +109,16 @@ async function removeWebTorrentFile (video: MVideoWithAllFiles, fileToDeleteId:
90 return removeAllWebTorrentFiles(video) 109 return removeAllWebTorrentFiles(video)
91 } 110 }
92 111
93 const toDelete = files.find(f => f.id === fileToDeleteId) 112 const videoFileMutexReleaser = await VideoPathManager.Instance.lockFiles(video.uuid)
94 await video.removeWebTorrentFile(toDelete) 113 try {
95 await toDelete.destroy() 114 const toDelete = files.find(f => f.id === fileToDeleteId)
115 await video.removeWebTorrentFile(toDelete)
116 await toDelete.destroy()
96 117
97 video.VideoFiles = files.filter(f => f.id !== toDelete.id) 118 video.VideoFiles = files.filter(f => f.id !== toDelete.id)
119 } finally {
120 videoFileMutexReleaser()
121 }
98 122
99 return video 123 return video
100} 124}