X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=scripts%2Fprune-storage.ts;h=c9e4dbd4b8094bead529388148c9ab0dda73a0a1;hb=f58094b2577afbd26bb2e74768938bcdd9890c16;hp=4088fa70046877e7a4620808b192f5addde15976;hpb=5ce1208a0a57d566b5b1fd57ec291a7d053ebaf0;p=github%2FChocobozzz%2FPeerTube.git diff --git a/scripts/prune-storage.ts b/scripts/prune-storage.ts index 4088fa700..c9e4dbd4b 100755 --- a/scripts/prune-storage.ts +++ b/scripts/prune-storage.ts @@ -5,6 +5,7 @@ import { VideoModel } from '../server/models/video/video' import { initDatabaseModels } from '../server/initializers' import { remove, readdir } from 'fs-extra' import { VideoRedundancyModel } from '../server/models/redundancy/video-redundancy' +import { getUUIDFromFilename } from '../server/helpers/utils' run() .then(() => process.exit(0)) @@ -18,7 +19,8 @@ async function run () { const storageOnlyOwnedToPrune = [ CONFIG.STORAGE.VIDEOS_DIR, - CONFIG.STORAGE.TORRENTS_DIR + CONFIG.STORAGE.TORRENTS_DIR, + CONFIG.STORAGE.REDUNDANCY_DIR ] const storageForAllToPrune = [ @@ -35,6 +37,9 @@ async function run () { toDelete = toDelete.concat(await pruneDirectory(directory, false)) } + const tmpFiles = await readdir(CONFIG.STORAGE.TMP_DIR) + toDelete = toDelete.concat(tmpFiles.map(t => join(CONFIG.STORAGE.TMP_DIR, t))) + if (toDelete.length === 0) { console.log('No files to delete.') return @@ -82,15 +87,6 @@ async function pruneDirectory (directory: string, onlyOwned = false) { return toDelete } -function getUUIDFromFilename (filename: string) { - const regex = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/ - const result = filename.match(regex) - - if (!result || Array.isArray(result) === false) return null - - return result[0] -} - async function askConfirmation () { return new Promise((res, rej) => { prompt.start() @@ -99,6 +95,7 @@ async function askConfirmation () { confirm: { type: 'string', description: 'These following unused files can be deleted, but please check your backups first (bugs happen).' + + ' Notice PeerTube must have been stopped when your ran this script.' + ' Can we delete these files?', default: 'n', required: true