aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-05-03 08:18:48 +0200
committerChocobozzz <me@florianbigard.com>2022-05-03 08:18:48 +0200
commit21d70a7302c0d03ae8cc538a97d4b279c4da5792 (patch)
treeaa07194c39d236465330ed574a9486ee7848c11f /server
parentb3d9dedcc36a333bae0bafe92eeede1a11796ce7 (diff)
downloadPeerTube-21d70a7302c0d03ae8cc538a97d4b279c4da5792.tar.gz
PeerTube-21d70a7302c0d03ae8cc538a97d4b279c4da5792.tar.zst
PeerTube-21d70a7302c0d03ae8cc538a97d4b279c4da5792.zip
Support readonly tmp directory
Diffstat (limited to 'server')
-rw-r--r--server/initializers/installer.ts20
1 files changed, 17 insertions, 3 deletions
diff --git a/server/initializers/installer.ts b/server/initializers/installer.ts
index 0517e0084..c18998244 100644
--- a/server/initializers/installer.ts
+++ b/server/initializers/installer.ts
@@ -1,4 +1,4 @@
1import { ensureDir, remove } from 'fs-extra' 1import { ensureDir, readdir, remove } from 'fs-extra'
2import passwordGenerator from 'password-generator' 2import passwordGenerator from 'password-generator'
3import { UserRole } from '@shared/models' 3import { UserRole } from '@shared/models'
4import { logger } from '../helpers/logger' 4import { logger } from '../helpers/logger'
@@ -50,14 +50,28 @@ function removeCacheAndTmpDirectories () {
50 // Cache directories 50 // Cache directories
51 for (const key of Object.keys(cacheDirectories)) { 51 for (const key of Object.keys(cacheDirectories)) {
52 const dir = cacheDirectories[key] 52 const dir = cacheDirectories[key]
53 tasks.push(remove(dir)) 53 tasks.push(removeDirectoryOrContent(dir))
54 } 54 }
55 55
56 tasks.push(remove(CONFIG.STORAGE.TMP_DIR)) 56 tasks.push(removeDirectoryOrContent(CONFIG.STORAGE.TMP_DIR))
57 57
58 return Promise.all(tasks) 58 return Promise.all(tasks)
59} 59}
60 60
61async function removeDirectoryOrContent (dir: string) {
62 try {
63 await remove(dir)
64 } catch (err) {
65 logger.debug('Cannot remove directory %s. Removing content instead.', dir, { err })
66
67 const files = await readdir(dir)
68
69 for (const file of files) {
70 await remove(file)
71 }
72 }
73}
74
61function createDirectoriesIfNotExist () { 75function createDirectoriesIfNotExist () {
62 const storage = CONFIG.STORAGE 76 const storage = CONFIG.STORAGE
63 const cacheDirectories = Object.keys(FILES_CACHE) 77 const cacheDirectories = Object.keys(FILES_CACHE)