Fix: creating working directories before extracting Prosody AppImage
This commit is contained in:
parent
459d92cef9
commit
27e8fbf05f
@ -22,33 +22,6 @@ async function getWorkingDir (options: RegisterServerOptions): Promise<string> {
|
|||||||
return dir
|
return dir
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates the working dir if needed, and returns it.
|
|
||||||
*/
|
|
||||||
async function ensureWorkingDir (options: RegisterServerOptions): Promise<string> {
|
|
||||||
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<ProsodyFilePaths> {
|
async function getProsodyFilePaths (options: RegisterServerOptions): Promise<ProsodyFilePaths> {
|
||||||
const logger = options.peertubeHelpers.logger
|
const logger = options.peertubeHelpers.logger
|
||||||
logger.debug('Calling getProsodyFilePaths')
|
logger.debug('Calling getProsodyFilePaths')
|
||||||
@ -221,8 +194,6 @@ async function writeProsodyConfig (options: RegisterServerOptions): Promise<Pros
|
|||||||
const logger = options.peertubeHelpers.logger
|
const logger = options.peertubeHelpers.logger
|
||||||
logger.debug('Calling writeProsodyConfig')
|
logger.debug('Calling writeProsodyConfig')
|
||||||
|
|
||||||
logger.debug('Ensuring that the working dir exists')
|
|
||||||
await ensureWorkingDir(options)
|
|
||||||
logger.debug('Computing the Prosody config content')
|
logger.debug('Computing the Prosody config content')
|
||||||
const config = await getProsodyConfig(options)
|
const config = await getProsodyConfig(options)
|
||||||
const content = config.content
|
const content = config.content
|
||||||
@ -298,7 +269,6 @@ function getProsodyConfigContentForDiagnostic (config: ProsodyConfig, content?:
|
|||||||
export {
|
export {
|
||||||
getProsodyConfig,
|
getProsodyConfig,
|
||||||
getWorkingDir,
|
getWorkingDir,
|
||||||
ensureWorkingDir,
|
|
||||||
getProsodyFilePaths,
|
getProsodyFilePaths,
|
||||||
writeProsodyConfig,
|
writeProsodyConfig,
|
||||||
getProsodyConfigContentForDiagnostic
|
getProsodyConfigContentForDiagnostic
|
||||||
|
@ -5,13 +5,45 @@ import { disableProxyRoute, enableProxyRoute } from '../routers/webchat'
|
|||||||
import * as fs from 'fs'
|
import * as fs from 'fs'
|
||||||
import * as child_process from 'child_process'
|
import * as child_process from 'child_process'
|
||||||
|
|
||||||
|
async function _ensureWorkingDir (
|
||||||
|
options: RegisterServerOptions,
|
||||||
|
workingDir: string,
|
||||||
|
dataDir: string
|
||||||
|
): Promise<string> {
|
||||||
|
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
|
* @param options
|
||||||
*/
|
*/
|
||||||
async function prepareProsody (options: RegisterServerOptions): Promise<void> {
|
async function prepareProsody (options: RegisterServerOptions): Promise<void> {
|
||||||
const logger = options.peertubeHelpers.logger
|
const logger = options.peertubeHelpers.logger
|
||||||
const filePaths = await getProsodyFilePaths(options)
|
const filePaths = await getProsodyFilePaths(options)
|
||||||
|
|
||||||
|
logger.debug('Ensuring that the working dir exists')
|
||||||
|
await _ensureWorkingDir(options, filePaths.dir, filePaths.data)
|
||||||
|
|
||||||
const appImageToExtract = filePaths.appImageToExtract
|
const appImageToExtract = filePaths.appImageToExtract
|
||||||
if (!appImageToExtract) {
|
if (!appImageToExtract) {
|
||||||
return
|
return
|
||||||
|
Loading…
x
Reference in New Issue
Block a user