diff options
Diffstat (limited to 'scripts/prune-storage.ts')
-rwxr-xr-x | scripts/prune-storage.ts | 17 |
1 files changed, 7 insertions, 10 deletions
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' | |||
5 | import { initDatabaseModels } from '../server/initializers' | 5 | import { initDatabaseModels } from '../server/initializers' |
6 | import { remove, readdir } from 'fs-extra' | 6 | import { remove, readdir } from 'fs-extra' |
7 | import { VideoRedundancyModel } from '../server/models/redundancy/video-redundancy' | 7 | import { VideoRedundancyModel } from '../server/models/redundancy/video-redundancy' |
8 | import { getUUIDFromFilename } from '../server/helpers/utils' | ||
8 | 9 | ||
9 | run() | 10 | run() |
10 | .then(() => process.exit(0)) | 11 | .then(() => process.exit(0)) |
@@ -18,7 +19,8 @@ async function run () { | |||
18 | 19 | ||
19 | const storageOnlyOwnedToPrune = [ | 20 | const storageOnlyOwnedToPrune = [ |
20 | CONFIG.STORAGE.VIDEOS_DIR, | 21 | CONFIG.STORAGE.VIDEOS_DIR, |
21 | CONFIG.STORAGE.TORRENTS_DIR | 22 | CONFIG.STORAGE.TORRENTS_DIR, |
23 | CONFIG.STORAGE.REDUNDANCY_DIR | ||
22 | ] | 24 | ] |
23 | 25 | ||
24 | const storageForAllToPrune = [ | 26 | const storageForAllToPrune = [ |
@@ -35,6 +37,9 @@ async function run () { | |||
35 | toDelete = toDelete.concat(await pruneDirectory(directory, false)) | 37 | toDelete = toDelete.concat(await pruneDirectory(directory, false)) |
36 | } | 38 | } |
37 | 39 | ||
40 | const tmpFiles = await readdir(CONFIG.STORAGE.TMP_DIR) | ||
41 | toDelete = toDelete.concat(tmpFiles.map(t => join(CONFIG.STORAGE.TMP_DIR, t))) | ||
42 | |||
38 | if (toDelete.length === 0) { | 43 | if (toDelete.length === 0) { |
39 | console.log('No files to delete.') | 44 | console.log('No files to delete.') |
40 | return | 45 | return |
@@ -82,15 +87,6 @@ async function pruneDirectory (directory: string, onlyOwned = false) { | |||
82 | return toDelete | 87 | return toDelete |
83 | } | 88 | } |
84 | 89 | ||
85 | function getUUIDFromFilename (filename: string) { | ||
86 | const regex = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/ | ||
87 | const result = filename.match(regex) | ||
88 | |||
89 | if (!result || Array.isArray(result) === false) return null | ||
90 | |||
91 | return result[0] | ||
92 | } | ||
93 | |||
94 | async function askConfirmation () { | 90 | async function askConfirmation () { |
95 | return new Promise((res, rej) => { | 91 | return new Promise((res, rej) => { |
96 | prompt.start() | 92 | prompt.start() |
@@ -99,6 +95,7 @@ async function askConfirmation () { | |||
99 | confirm: { | 95 | confirm: { |
100 | type: 'string', | 96 | type: 'string', |
101 | description: 'These following unused files can be deleted, but please check your backups first (bugs happen).' + | 97 | description: 'These following unused files can be deleted, but please check your backups first (bugs happen).' + |
98 | ' Notice PeerTube must have been stopped when your ran this script.' + | ||
102 | ' Can we delete these files?', | 99 | ' Can we delete these files?', |
103 | default: 'n', | 100 | default: 'n', |
104 | required: true | 101 | required: true |