From 43e71b3d3286ae57c983c4b6ed74998e19c25876 Mon Sep 17 00:00:00 2001 From: Linus Lundahl Date: Thu, 19 Sep 2024 13:38:33 +0200 Subject: [PATCH] Allow apps to be defined as installer in packaging_info --- .../common/src/entities/dbmss/dbmss.local.ts | 4 +++- .../common/src/utils/dbmss/extract-neo4j.ts | 23 ++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/packages/common/src/entities/dbmss/dbmss.local.ts b/packages/common/src/entities/dbmss/dbmss.local.ts index fb03ff2a8..1fc2ed714 100644 --- a/packages/common/src/entities/dbmss/dbmss.local.ts +++ b/packages/common/src/entities/dbmss/dbmss.local.ts @@ -137,10 +137,12 @@ export class LocalDbmss extends DbmssAbstract { throw new DbmsExistsError(`DBMS with name "${name}" already exists`); } + const installer = this.environment.name.replace('_', ''); + // version as a file path. if ((await fse.pathExists(version)) && (await fse.stat(version)).isFile()) { const tmpPath = path.join(this.environment.dirPaths.tmp, uuidv4()); - const {extractedDistPath} = await extractNeo4j(version, tmpPath); + const {extractedDistPath} = await extractNeo4j(version, tmpPath, installer); const {version: semverVersion} = await getDistributionVersion(extractedDistPath); const dbms = await this.installNeo4j( diff --git a/packages/common/src/utils/dbmss/extract-neo4j.ts b/packages/common/src/utils/dbmss/extract-neo4j.ts index 1a80c187d..e92da8dce 100644 --- a/packages/common/src/utils/dbmss/extract-neo4j.ts +++ b/packages/common/src/utils/dbmss/extract-neo4j.ts @@ -1,3 +1,6 @@ +import fse from 'fs-extra'; +import path from 'path'; + import {HOOK_EVENTS} from '../../constants'; import {FileStructureError} from '../../errors'; import {IDbmsVersion} from '../../models'; @@ -9,9 +12,27 @@ interface IExtractedArchive extends IDbmsVersion { extractedDistPath: string; } -export const extractNeo4j = async (archivePath: string, outputDir: string): Promise => { +const addPackageInfo = async (dir: string, installer?: string) => { + if (installer === undefined) { + return; + } + + const packageInfoFile = path.join(dir, 'packaging_info'); + const packageInfo = await fse.readFile(packageInfoFile, 'utf8'); + const newPackageInfo = packageInfo.replace(/Package Type: (.*)/gm, `Package Type: ${installer}`); + await fse.writeFile(packageInfoFile, newPackageInfo, 'utf8'); +}; + +export const extractNeo4j = async ( + archivePath: string, + outputDir: string, + installer?: string, +): Promise => { await emitHookEvent(HOOK_EVENTS.NEO4J_EXTRACT_START, 'extracting neo4j'); const extractedDistPath = await extract(archivePath, outputDir); + await addPackageInfo(extractedDistPath, installer).catch(() => { + // Do nothing + }); await emitHookEvent(HOOK_EVENTS.NEO4J_EXTRACT_STOP, null); // check if this is neo4j...