Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
feat(import/zip): ignore macOS metadata
Elian Dorana191813dc203
diff --git a/packages/trilium-core/src/services/import/zip.ts b/packages/trilium-core/src/services/import/zip.tsindex 8bd6a0e3a8..a4fe308db5 100644--- a/packages/trilium-core/src/services/import/zip.ts+++ b/packages/trilium-core/src/services/import/zip.ts@@ -629,6 +629,10 @@ async function importZip(taskContext: TaskContext<"importNotes">, fileBuffer: Uiawait zipProvider.readZipFile(fileBuffer, async (entry, readContent) => {const filePath = normalizeFilePath(entry.fileName);+ if (isMacOSMetadata(filePath)) {+ return;+ }+// make sure that the meta file is loaded before the rest of the files is processed.if (filePath === "!!!meta.json") {const content = await readContent();@@ -646,6 +650,10 @@ async function importZip(taskContext: TaskContext<"importNotes">, fileBuffer: Uiawait zipProvider.readZipFile(fileBuffer, async (entry, readContent) => {const filePath = normalizeFilePath(entry.fileName);+ if (isMacOSMetadata(filePath)) {+ return;+ }+if (/\/$/.test(entry.fileName)) {saveDirectory(filePath);} else if (filePath !== "!!!meta.json") {@@ -686,6 +694,11 @@ async function importZip(taskContext: TaskContext<"importNotes">, fileBuffer: Uireturn firstNote;}+/** Skips macOS resource fork metadata that pollutes ZIP archives created on macOS. */+function isMacOSMetadata(filePath: string): boolean {+ return filePath.startsWith("__MACOSX/") || filePath === "__MACOSX";+}+/** @returns path without leading or trailing slash and backslashes converted to forward ones */function normalizeFilePath(filePath: string): string {filePath = filePath.replace(/\\/g, "/");