Skip to content

Commit

Permalink
fix tmp directory usage
Browse files Browse the repository at this point in the history
  • Loading branch information
erhant committed Feb 20, 2024
1 parent c1e96cc commit 35b457e
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>",
"contributors": [
"Erhan Tezcan <[email protected]> (https://github.com/erhant)"
],
"homepage": "https://github.com/firstbatchxyz/dria-cli#readme",
"license": "Apache-2.0",
"files": [
"/bin",
Expand Down
2 changes: 1 addition & 1 deletion src/commands/pull.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { logger, safeRemoveContainer } from "../common";
import { logger } from "../common";
import constants from "../constants";
import { hollowdbContainer, redisContainer } from "../containers";

Expand Down
7 changes: 5 additions & 2 deletions src/common/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 35b457e

Please sign in to comment.