1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-05 02:39:33 +02:00

Correctly cleanup permanent live empty directories

This commit is contained in:
Chocobozzz 2024-09-11 14:45:02 +02:00
parent be7bc3a6a9
commit 71bdad9f5e
No known key found for this signature in database
GPG key ID: 583A612D890159BE
3 changed files with 40 additions and 17 deletions

View file

@ -1,12 +1,12 @@
import { pathExists, remove } from 'fs-extra/esm'
import { readdir } from 'fs/promises'
import { readdir, rmdir } from 'fs/promises'
import { basename, join } from 'path'
import { LiveVideoLatencyMode, LiveVideoLatencyModeType, FileStorage } from '@peertube/peertube-models'
import { LiveVideoLatencyMode, LiveVideoLatencyModeType, FileStorage, VideoState } from '@peertube/peertube-models'
import { logger } from '@server/helpers/logger.js'
import { VIDEO_LIVE } from '@server/initializers/constants.js'
import { MStreamingPlaylist, MStreamingPlaylistVideo, MVideo } from '@server/types/models/index.js'
import { listHLSFileKeysOf, removeHLSFileObjectStorageByFullKey, removeHLSObjectStorage } from '../object-storage/index.js'
import { getLiveDirectory } from '../paths.js'
import { getLiveDirectory, getLiveReplayBaseDirectory } from '../paths.js'
function buildConcatenatedName (segmentOrPlaylistPath: string) {
const num = basename(segmentOrPlaylistPath).match(/^(\d+)(-|\.)/)
@ -17,6 +17,17 @@ function buildConcatenatedName (segmentOrPlaylistPath: string) {
async function cleanupAndDestroyPermanentLive (video: MVideo, streamingPlaylist: MStreamingPlaylist) {
await cleanupTMPLiveFiles(video, streamingPlaylist)
if (video.state === VideoState.WAITING_FOR_LIVE) {
// Try to delete local filesystem empty paths
// Object storage doesn't have the concept of directories so we don't need to duplicate the logic here
try {
await rmdir(getLiveReplayBaseDirectory(video))
await rmdir(getLiveDirectory(video))
} catch (err) {
logger.debug('Cannot cleanup permanent local live files', { err })
}
}
await streamingPlaylist.destroy()
}