From 5a0641904ae1d054801eaf1a068dd061f42ba634 Mon Sep 17 00:00:00 2001 From: Nick Playfair <842413+nplayfair@users.noreply.github.com> Date: Fri, 13 Jun 2025 21:12:24 +0100 Subject: [PATCH] Use default node fs for dir checking --- index.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index aa0aa0e..6bd4ec4 100644 --- a/index.js +++ b/index.js @@ -6,6 +6,7 @@ const pcbStackup = require('pcb-stackup'); const sharp = require('sharp'); const { Readable } = require('stream'); const { Buffer } = require('node:buffer'); +const { existsSync, accessSync, constants } = require('node:fs'); //Class definition class ImageGenerator { @@ -15,10 +16,18 @@ class ImageGenerator { this.imgConfig = imgConfig; this.layerNames = layerNames; - // Ensure that the folders exist + //Ensure folders exist try { - fs.ensureDirSync(this.tmpDir); - fs.ensureDirSync(this.imgDir); + if (!existsSync(this.tmpDir)) throw 'Temp dir does not exist'; + if (!existsSync(this.imgDir)) throw 'Image dir does not exist'; + } catch (error) { + throw new Error(error); + } + + //Check folder permissions + try { + accessSync(this.tmpDir, constants.R_OK | constants.W_OK); + accessSync(this.imgDir, constants.R_OK | constants.W_OK); } catch (error) { throw new Error(error); }