diff --git a/server/lib/prosody/config.ts b/server/lib/prosody/config.ts index f8e414d6..7c7ba17a 100644 --- a/server/lib/prosody/config.ts +++ b/server/lib/prosody/config.ts @@ -22,33 +22,6 @@ async function getWorkingDir (options: RegisterServerOptions): Promise { return dir } -/** - * Creates the working dir if needed, and returns it. - */ -async function ensureWorkingDir (options: RegisterServerOptions): Promise { - const logger = options.peertubeHelpers.logger - logger.debug('Calling ensureworkingDir') - - const paths = await getProsodyFilePaths(options) - const dir = paths.dir - if (!fs.existsSync(dir)) { - logger.info(`The working dir ${dir} does not exists, trying to create it`) - await fs.promises.mkdir(dir) - logger.debug(`Working dir ${dir} was created`) - } - logger.debug(`Testing write access on ${dir}`) - await fs.promises.access(dir, fs.constants.W_OK) // will throw an error if no access - logger.debug(`Write access ok on ${dir}`) - - if (!fs.existsSync(paths.data)) { - logger.info(`The data dir ${paths.data} does not exists, trying to create it`) - await fs.promises.mkdir(paths.data) - logger.debug(`Working dir ${paths.data} was created`) - } - - return dir -} - async function getProsodyFilePaths (options: RegisterServerOptions): Promise { const logger = options.peertubeHelpers.logger logger.debug('Calling getProsodyFilePaths') @@ -221,8 +194,6 @@ async function writeProsodyConfig (options: RegisterServerOptions): Promise { + const logger = options.peertubeHelpers.logger + logger.debug('Calling ensureworkingDir') + + if (!fs.existsSync(workingDir)) { + logger.info(`The working dir ${workingDir} does not exists, trying to create it`) + await fs.promises.mkdir(workingDir) + logger.debug(`Working dir ${workingDir} was created`) + } + logger.debug(`Testing write access on ${workingDir}`) + await fs.promises.access(workingDir, fs.constants.W_OK) // will throw an error if no access + logger.debug(`Write access ok on ${workingDir}`) + + if (!fs.existsSync(dataDir)) { + logger.info(`The data dir ${dataDir} does not exists, trying to create it`) + await fs.promises.mkdir(dataDir) + logger.debug(`Working dir ${dataDir} was created`) + } + + return workingDir +} + /** - * This function prepares the binaries for the embeded Prosody (if needed). + * This function prepares: + * - the Prosody working dir + * - the binaries for the embeded Prosody (if needed). * @param options */ async function prepareProsody (options: RegisterServerOptions): Promise { const logger = options.peertubeHelpers.logger const filePaths = await getProsodyFilePaths(options) + + logger.debug('Ensuring that the working dir exists') + await _ensureWorkingDir(options, filePaths.dir, filePaths.data) + const appImageToExtract = filePaths.appImageToExtract if (!appImageToExtract) { return