diff options
Diffstat (limited to 'server/initializers')
-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) |