Skip to content

Commit

Permalink
fix: check if folder exists before pre-purging it
Browse files Browse the repository at this point in the history
  • Loading branch information
mcarvin8 committed Mar 12, 2024
1 parent 4caf5fa commit 391d37b
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/service/disassembleXMLFileHandler.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as fs from "node:fs/promises";
import * as fs from "node:fs";
import * as promises from "node:fs/promises";
import * as path from "node:path";
import { logger } from "@src/index";
import { INDENT } from "@src/helpers/constants";
Expand All @@ -17,7 +18,7 @@ export class DisassembleXMLFileHandler {
prePurge = false,
postPurge = false,
} = xmlAttributes;
const fileStat = await fs.stat(xmlPath);
const fileStat = await promises.stat(xmlPath);

if (fileStat.isFile()) {
const filePath = path.resolve(xmlPath);
Expand All @@ -34,7 +35,7 @@ export class DisassembleXMLFileHandler {
postPurge,
});
} else if (fileStat.isDirectory()) {
const files = await fs.readdir(xmlPath);
const files = await promises.readdir(xmlPath);
for (const file of files) {
const filePath = path.join(xmlPath, file);
if (filePath.endsWith(".xml")) {
Expand All @@ -61,15 +62,17 @@ export class DisassembleXMLFileHandler {
xmlAttributes;

logger.debug(`Parsing file to disassemble: ${filePath}`);
const xmlContent = await fs.readFile(filePath, "utf-8");
const xmlContent = await promises.readFile(filePath, "utf-8");
const fullName = path.basename(filePath, path.extname(filePath));
const baseName = fullName.split(".")[0];

let outputPath;
outputPath = path.join(xmlPath, baseName);

if (prePurge) {
await fs.rm(outputPath, { recursive: true });
if (fs.existsSync(outputPath)) {
await promises.rm(outputPath, { recursive: true });
}
}

buildDisassembledFiles(
Expand Down

0 comments on commit 391d37b

Please sign in to comment.