⚡️⚡️⚡️ Self-hosted collaborative bookmark manager to collect, read, annotate, and fully preserve what matters, all in one place.
TypeScript bookmarkbookmark-managercollaborationnextjsreact-nativeread-it-laterself-hostedtypescript
fix: ignore missing local archive deletes
Anthomosf08ea636f170
diff --git a/packages/filesystem/removeFile.test.ts b/packages/filesystem/removeFile.test.tsnew file mode 100644index 00000000..844ba2ed--- /dev/null+++ b/packages/filesystem/removeFile.test.ts@@ -0,0 +1,43 @@+import fs from "fs";+import { afterEach, describe, expect, it, vi } from "vitest";+import { removeFile } from "./removeFile";++vi.mock("fs", () => ({+ default: {+ unlink: vi.fn(),+ },+}));++vi.mock("./s3Client", () => ({+ default: null,+}));++describe("removeFile", () => {+ const consoleLog = vi.spyOn(console, "log").mockImplementation(() => {});++ afterEach(() => {+ vi.clearAllMocks();+ delete process.env.STORAGE_FOLDER;+ });++ it("ignores missing local files", async () => {+ vi.mocked(fs.unlink).mockImplementation((_path, callback) => {+ callback({ code: "ENOENT" } as NodeJS.ErrnoException);+ });++ await removeFile({ filePath: "archives/1/2.jpg" });++ expect(consoleLog).not.toHaveBeenCalled();+ });++ it("logs unexpected local delete errors", async () => {+ const error = { code: "EACCES" } as NodeJS.ErrnoException;+ vi.mocked(fs.unlink).mockImplementation((_path, callback) => {+ callback(error);+ });++ await removeFile({ filePath: "archives/1/2.jpg" });++ expect(consoleLog).toHaveBeenCalledWith(error);+ });+});diff --git a/packages/filesystem/removeFile.ts b/packages/filesystem/removeFile.tsindex d405002f..1af48796 100644--- a/packages/filesystem/removeFile.ts+++ b/packages/filesystem/removeFile.ts@@ -25,7 +25,7 @@ export async function removeFile({ filePath }: { filePath: string }) {);fs.unlink(creationPath, (err) => {- if (err) console.log(err);+ if (err && err.code !== "ENOENT") console.log(err);});}}