diff options
author | Chocobozzz <me@florianbigard.com> | 2022-05-03 08:18:48 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2022-05-03 08:18:48 +0200 |
commit | 21d70a7302c0d03ae8cc538a97d4b279c4da5792 (patch) | |
tree | aa07194c39d236465330ed574a9486ee7848c11f /server | |
parent | b3d9dedcc36a333bae0bafe92eeede1a11796ce7 (diff) | |
download | PeerTube-21d70a7302c0d03ae8cc538a97d4b279c4da5792.tar.gz PeerTube-21d70a7302c0d03ae8cc538a97d4b279c4da5792.tar.zst PeerTube-21d70a7302c0d03ae8cc538a97d4b279c4da5792.zip |
Support readonly tmp directory
Diffstat (limited to 'server')
-rw-r--r-- | server/initializers/installer.ts | 20 |
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 @@ | |||
1 | import { ensureDir, remove } from 'fs-extra' | 1 | import { ensureDir, readdir, remove } from 'fs-extra' |
2 | import passwordGenerator from 'password-generator' | 2 | import passwordGenerator from 'password-generator' |
3 | import { UserRole } from '@shared/models' | 3 | import { UserRole } from '@shared/models' |
4 | import { logger } from '../helpers/logger' | 4 | import { 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 | ||
61 | async 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 | |||
61 | function createDirectoriesIfNotExist () { | 75 | function 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) |