From 92083e42289e19033425672dfbe2234aef03c6df Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 24 Jun 2022 09:34:56 +0200 Subject: Fix removed sha segments on fast restream --- server/lib/live/live-manager.ts | 5 +---- server/lib/live/live-utils.ts | 15 +++++++++++---- 2 files changed, 12 insertions(+), 8 deletions(-) (limited to 'server/lib/live') diff --git a/server/lib/live/live-manager.ts b/server/lib/live/live-manager.ts index f2f064b49..d499b4b1a 100644 --- a/server/lib/live/live-manager.ts +++ b/server/lib/live/live-manager.ts @@ -27,7 +27,6 @@ import { JobQueue } from '../job-queue' import { generateHLSMasterPlaylistFilename, generateHlsSha256SegmentsFilename, getLiveReplayBaseDirectory } from '../paths' import { PeerTubeSocket } from '../peertube-socket' import { LiveQuotaStore } from './live-quota-store' -import { LiveSegmentShaStore } from './live-segment-sha-store' import { cleanupPermanentLive } from './live-utils' import { MuxingSession } from './shared' @@ -219,9 +218,7 @@ class LiveManager { return this.abortSession(sessionId) } - // Cleanup old potential live files (could happen with a permanent live) - LiveSegmentShaStore.Instance.cleanupShaSegments(video.uuid) - + // Cleanup old potential live (could happen with a permanent live) const oldStreamingPlaylist = await VideoStreamingPlaylistModel.loadHLSPlaylistByVideo(video.id) if (oldStreamingPlaylist) { if (!videoLive.permanentLive) throw new Error('Found previous session in a non permanent live: ' + video.uuid) diff --git a/server/lib/live/live-utils.ts b/server/lib/live/live-utils.ts index 6305a97a8..bba876642 100644 --- a/server/lib/live/live-utils.ts +++ b/server/lib/live/live-utils.ts @@ -3,6 +3,7 @@ import { basename, join } from 'path' import { logger } from '@server/helpers/logger' import { MStreamingPlaylist, MVideo } from '@server/types/models' import { getLiveDirectory } from '../paths' +import { LiveSegmentShaStore } from './live-segment-sha-store' function buildConcatenatedName (segmentOrPlaylistPath: string) { const num = basename(segmentOrPlaylistPath).match(/^(\d+)(-|\.)/) @@ -11,9 +12,7 @@ function buildConcatenatedName (segmentOrPlaylistPath: string) { } async function cleanupPermanentLive (video: MVideo, streamingPlaylist: MStreamingPlaylist) { - const hlsDirectory = getLiveDirectory(video) - - await cleanupTMPLiveFiles(hlsDirectory) + await cleanupTMPLiveFiles(video) await streamingPlaylist.destroy() } @@ -24,11 +23,19 @@ async function cleanupUnsavedNormalLive (video: MVideo, streamingPlaylist: MStre await remove(hlsDirectory) await streamingPlaylist.destroy() + + LiveSegmentShaStore.Instance.cleanupShaSegments(video.uuid) } -async function cleanupTMPLiveFiles (hlsDirectory: string) { +async function cleanupTMPLiveFiles (video: MVideo) { + const hlsDirectory = getLiveDirectory(video) + + LiveSegmentShaStore.Instance.cleanupShaSegments(video.uuid) + if (!await pathExists(hlsDirectory)) return + logger.info('Cleanup TMP live files of %s.', hlsDirectory) + const files = await readdir(hlsDirectory) for (const filename of files) { -- cgit v1.2.3