Support readonly tmp directory
This commit is contained in:
parent
b3d9dedcc3
commit
21d70a7302
|
@ -1,4 +1,4 @@
|
||||||
import { ensureDir, remove } from 'fs-extra'
|
import { ensureDir, readdir, remove } from 'fs-extra'
|
||||||
import passwordGenerator from 'password-generator'
|
import passwordGenerator from 'password-generator'
|
||||||
import { UserRole } from '@shared/models'
|
import { UserRole } from '@shared/models'
|
||||||
import { logger } from '../helpers/logger'
|
import { logger } from '../helpers/logger'
|
||||||
|
@ -50,14 +50,28 @@ function removeCacheAndTmpDirectories () {
|
||||||
// Cache directories
|
// Cache directories
|
||||||
for (const key of Object.keys(cacheDirectories)) {
|
for (const key of Object.keys(cacheDirectories)) {
|
||||||
const dir = cacheDirectories[key]
|
const dir = cacheDirectories[key]
|
||||||
tasks.push(remove(dir))
|
tasks.push(removeDirectoryOrContent(dir))
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.push(remove(CONFIG.STORAGE.TMP_DIR))
|
tasks.push(removeDirectoryOrContent(CONFIG.STORAGE.TMP_DIR))
|
||||||
|
|
||||||
return Promise.all(tasks)
|
return Promise.all(tasks)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function removeDirectoryOrContent (dir: string) {
|
||||||
|
try {
|
||||||
|
await remove(dir)
|
||||||
|
} catch (err) {
|
||||||
|
logger.debug('Cannot remove directory %s. Removing content instead.', dir, { err })
|
||||||
|
|
||||||
|
const files = await readdir(dir)
|
||||||
|
|
||||||
|
for (const file of files) {
|
||||||
|
await remove(file)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function createDirectoriesIfNotExist () {
|
function createDirectoriesIfNotExist () {
|
||||||
const storage = CONFIG.STORAGE
|
const storage = CONFIG.STORAGE
|
||||||
const cacheDirectories = Object.keys(FILES_CACHE)
|
const cacheDirectories = Object.keys(FILES_CACHE)
|
||||||
|
|
Loading…
Reference in New Issue