aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/initializers/installer.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/initializers/installer.ts')
-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)