Skip to content

Commit

Permalink
Fixed issue with deleting original when cant reach save limit
Browse files Browse the repository at this point in the history
  • Loading branch information
lemehovskiy committed Apr 21, 2024
1 parent f805c2f commit 26c6b0b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,15 @@ export function activate(context: vscode.ExtensionContext) {
if (!buffer) return;
const webpPath = getWebPPath(path);

writeFileWhenPassSaveLimit(
const writeOk = writeFileWhenPassSaveLimit(
path,
webpPath,
buffer,
SAVE_LIMIT,
OPERATIONS_TYPES.ConvertToWebP,
);

if (DELETE_ORIGINAL) {
if (writeOk && DELETE_ORIGINAL) {
fs.unlinkSync(path);
}
},
Expand Down
4 changes: 2 additions & 2 deletions src/utils/writeFileWhenPassSaveLimit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import { OPERATIONS_TYPES } from "../types";
import { checkIfCanReachSaveLimit } from "./checkIfCanReachSaveLimit";
import { writeToFile } from "./writeToFile";

export async function writeFileWhenPassSaveLimit(
export function writeFileWhenPassSaveLimit(
path: string,
writePath: string,
buffer: { data: Buffer; info: OutputInfo },
SAVE_LIMIT: number,
operationType: OPERATIONS_TYPES,
) {
if (checkIfCanReachSaveLimit(path, buffer.info.size, SAVE_LIMIT)) {
writeToFile(writePath, buffer.data, operationType);
return writeToFile(writePath, buffer.data, operationType);
} else {
throw new Error(`Save is less than ${SAVE_LIMIT}%`);
}
Expand Down
2 changes: 2 additions & 0 deletions src/utils/writeToFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@ export const writeToFile = (
}

fs.writeFileSync(newPath, buffer);

return true;
};

0 comments on commit 26c6b0b

Please sign in to comment.