From 35b457eca335728d9e68a15a87e8c1f5c1213b49 Mon Sep 17 00:00:00 2001 From: erhant Date: Tue, 20 Feb 2024 18:58:07 +0300 Subject: [PATCH] fix tmp directory usage --- package.json | 3 ++- src/commands/pull.ts | 2 +- src/common/download.ts | 7 +++++-- src/constants/index.ts | 2 ++ 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index ff13a98..99e7395 100644 --- a/package.json +++ b/package.json @@ -1,11 +1,12 @@ { "name": "dria-cli", - "version": "0.0.5", + "version": "0.0.6", "description": "A command-line tool for Dria", "author": "FirstBatch Team ", "contributors": [ "Erhan Tezcan (https://github.com/erhant)" ], + "homepage": "https://github.com/firstbatchxyz/dria-cli#readme", "license": "Apache-2.0", "files": [ "/bin", diff --git a/src/commands/pull.ts b/src/commands/pull.ts index d6688cf..efb08e7 100644 --- a/src/commands/pull.ts +++ b/src/commands/pull.ts @@ -1,4 +1,4 @@ -import { logger, safeRemoveContainer } from "../common"; +import { logger } from "../common"; import constants from "../constants"; import { hollowdbContainer, redisContainer } from "../containers"; diff --git a/src/common/download.ts b/src/common/download.ts index 0d6e51d..918b163 100644 --- a/src/common/download.ts +++ b/src/common/download.ts @@ -2,7 +2,7 @@ import Axios from "axios"; import unzipper from "unzipper"; import constants from "../constants"; import { logger } from "."; -import { createReadStream, createWriteStream, rmSync } from "fs"; +import { createReadStream, createWriteStream, existsSync, mkdirSync, rmSync } from "fs"; /** Download a zipped data from Arweave, unzip & extract it at a given path. * @@ -17,7 +17,10 @@ export async function downloadAndUnzip(txId: string, outDir: string) { logger.info("Downloading from", url); // download the file using a stream (due to large size) - const tmpPath = `/tmp/${txId}.zip`; + if (!existsSync(constants.DRIA.TMP)) { + mkdirSync(constants.DRIA.TMP, { recursive: true }); + } + const tmpPath = `${constants.DRIA.TMP}/${txId}.zip`; const writer = createWriteStream(tmpPath); await Axios({ url, diff --git a/src/constants/index.ts b/src/constants/index.ts index f458390..111d671 100644 --- a/src/constants/index.ts +++ b/src/constants/index.ts @@ -18,6 +18,8 @@ export default { CONFIG: `${DRIA_ROOT}/.driarc.json`, /** Path to Dria pulled contract data directory. */ DATA: resolve(`${DRIA_ROOT}/data`), + /** Temporary Dria path, used for zip buffer. */ + TMP: resolve(`${DRIA_ROOT}/tmp`), } as const, HOLLOWDB: { DOWNLOAD_TIMEOUT: 10000, // timeout until download starts, otherwise rejects