X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Finitializers%2Finstaller.ts;h=b02be956702505add2383ba165777c202f692f13;hb=84cae54e7a2595bea0c3ea106a4d111fd11a4ec6;hp=0517e00840725ad33926d58b5db3aedff4949746;hpb=7b51ede977c299a74728171d8c124bcc4cbba6ea;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/initializers/installer.ts b/server/initializers/installer.ts index 0517e0084..b02be9567 100644 --- a/server/initializers/installer.ts +++ b/server/initializers/installer.ts @@ -1,5 +1,8 @@ -import { ensureDir, remove } from 'fs-extra' +import { ensureDir, readdir, remove } from 'fs-extra' import passwordGenerator from 'password-generator' +import { join } from 'path' +import { isTestOrDevInstance } from '@server/helpers/core-utils' +import { getNodeABIVersion } from '@server/helpers/version' import { UserRole } from '@shared/models' import { logger } from '../helpers/logger' import { buildUser, createApplicationActor, createUserAccountAndChannelAndPlaylist } from '../lib/user' @@ -50,14 +53,28 @@ function removeCacheAndTmpDirectories () { // Cache directories for (const key of Object.keys(cacheDirectories)) { 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) } +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(join(dir, file)) + } + } +} + function createDirectoriesIfNotExist () { const storage = CONFIG.STORAGE const cacheDirectories = Object.keys(FILES_CACHE) @@ -120,8 +137,8 @@ async function createOAuthAdminIfNotExist () { let validatePassword = true let password = '' - // Do not generate a random password for tests - if (process.env.NODE_ENV === 'test') { + // Do not generate a random password for test and dev environments + if (isTestOrDevInstance()) { password = 'test' if (process.env.NODE_APP_INSTANCE) { @@ -159,7 +176,9 @@ async function createApplicationIfNotExist () { logger.info('Creating application account.') const application = await ApplicationModel.create({ - migrationVersion: LAST_MIGRATION_VERSION + migrationVersion: LAST_MIGRATION_VERSION, + nodeVersion: process.version, + nodeABIVersion: getNodeABIVersion() }) return createApplicationActor(application.id)