1
0
mirror of https://github.com/upscayl/upscayl.git synced 2024-09-24 03:18:28 +02:00

Fix temp folder delete bug

This commit is contained in:
Nayam Amarshe 2023-11-26 18:36:23 +05:30
parent 00520494cd
commit c77e0f6c92
2 changed files with 22 additions and 7 deletions

View File

@ -1,4 +1,4 @@
import fs from "fs";
import fs, { rmdir } from "fs";
import { getMainWindow } from "../main-window";
import {
childProcesses,
@ -61,7 +61,6 @@ const batchUpscayl = async (event, payload: BatchUpscaylPayload) => {
if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir, { recursive: true });
}
// Create a folder in the output directory to store the original images
if (!fs.existsSync(tempDirectory)) {
fs.mkdirSync(tempDirectory, { recursive: true });
@ -140,7 +139,7 @@ const batchUpscayl = async (event, payload: BatchUpscaylPayload) => {
mainWindow.webContents.send(COMMAND.FOLDER_UPSCAYL_DONE, outputDir);
return;
}
// Get number of files in output folder
const files = fs.readdirSync(tempDirectory);
try {
files.forEach(async (file) => {
@ -153,13 +152,25 @@ const batchUpscayl = async (event, payload: BatchUpscaylPayload) => {
saveImageAs,
onError
);
});
files.forEach(async (file) => {
// Remove the png file (default) if the saveImageAs is not png
if (saveImageAs !== "png") {
fs.unlinkSync(outputDir + slash + file.slice(0, -3) + "png");
}
});
mainWindow.webContents.send(COMMAND.FOLDER_UPSCAYL_DONE, outputDir);
fs.rmdirSync(tempDirectory, { recursive: true });
rmdir(
tempDirectory,
{
recursive: true,
},
(err) => {
if (err) {
logit("🚫 Error deleting temp folder", err);
}
}
);
} catch (error) {
logit("❌ Error processing (scaling and converting) the image.", error);
upscayl.kill();
@ -169,7 +180,6 @@ const batchUpscayl = async (event, payload: BatchUpscaylPayload) => {
"Error processing (scaling and converting) the image. Please report this error on Upscayl GitHub Issues page.\n" +
error
);
fs.rmdirSync(tempDirectory, { recursive: true });
}
} else {
upscayl.kill();

View File

@ -1,5 +1,5 @@
import fs from "fs";
import sharp, { FormatEnum } from "sharp";
import sharp, { FormatEnum, Metadata } from "sharp";
import logit from "./logit";
import { getMainWindow } from "../main-window";
import { compression } from "./config-variables";
@ -17,8 +17,13 @@ const convertAndScale = async (
return;
}
const mainWindow = getMainWindow();
let originalImage: Metadata | undefined;
const originalImage = await sharp(originalImagePath).metadata();
try {
originalImage = await sharp(originalImagePath).metadata();
} catch (error) {
logit("❌ Error with original Image: ", error);
}
fs.access(originalImagePath, fs.constants.F_OK, (err) => {
if (err) {