Skip to content

Commit

Permalink
fix: temp dir should be a temp dir (#10)
Browse files Browse the repository at this point in the history
chore: use the promise version of `tmp`.

Co-authored-by: Chris Howe <[email protected]>
  • Loading branch information
robertshuford and howech authored Oct 29, 2024
1 parent 190cc55 commit 7d8f24e
Showing 1 changed file with 7 additions and 19 deletions.
26 changes: 7 additions & 19 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ const { exec, spawn, execSync } = require("child_process");
const fs = require("fs").promises;
const kill = require("kill-port");
const { z } = require("zod");
const tmp = require("tmp-promise")
tmp.setGracefulCleanup()

// Temporary directory location
let tempDir

// Schema Definitions
const GpgKeySchema = z.object({
Expand Down Expand Up @@ -143,14 +148,8 @@ async function handleSignRequest(ws, messageToSign, fingerprint) {
// Decode the message from base64
const decodedMessage = Buffer.from(messageToSign, "base64");

// Define the temporary directory path
const tempDir = path.join(__dirname, "temp");

// Ensure the 'temp' directory exists
await fs.mkdir(tempDir, { recursive: true });

// Define the temporary file path
const tempFilePath = path.join(tempDir, `message_${Date.now()}.txt`);
const tempFilePath = path.join(tempDir.name, `message_${Date.now()}.txt`);
await fs.writeFile(tempFilePath, decodedMessage);

// Notify the client about the signing process
Expand Down Expand Up @@ -357,18 +356,7 @@ function sendMessage(ws, payload) {

// Initialize Temporary Directory on App Startup
async function initializeApp() {
// Define the temporary directory path
const tempDir = path.join(__dirname, "temp");

// Ensure the 'temp' directory exists
try {
await fs.mkdir(tempDir, { recursive: true });
console.log("Temp directory is ready.");
} catch (error) {
console.error("Failed to create temp directory:", error);
// You might choose to quit the app if temp directory creation fails
app.quit();
}
tempDir = await tmp.dir()

// Continue with other initialization tasks if necessary
}
Expand Down

0 comments on commit 7d8f24e

Please sign in to comment.