zadam / trilium

Build your personal knowledge base with Trilium Notes
GNU Affero General Public License v3.0
27.2k stars 1.9k forks source link

(Bug report) zip file compatibility #2440

Closed Nriver closed 2 years ago

Nriver commented 2 years ago

Preflight Checklist

Trilium Version

0.48.8

What operating system are you using?

Other Linux

What is your setup?

Local (no sync)

Operating System Version

Manjaro

Expected Behavior

I open a fresh Trilium Note with the portable command. And delete all the note after initialize.

I unzipped the built-in demo.zip file on the 0.48 release. Unzip it with unzip demo.zip -d demo, then make a new zip file with cd demo && zip -r demo.zip *.

Then try to import this file to trilium.

Actual Behavior

Trilium gives the following error:

TypeError: Cannot read property 'startsWith' of undefined
    at Object.isStringNote (/home/nate/soft/trilium/trilium-trans/trilium-linux-x64/resources/app/src/services/utils.js:172:17)
    at Note.isStringNote (/home/nate/soft/trilium/trilium-trans/trilium-linux-x64/resources/app/src/becca/entities/note.js:301:22)
    at Note.setContent (/home/nate/soft/trilium/trilium-trans/trilium-linux-x64/resources/app/src/becca/entities/note.js:234:18)
    at saveNote (/home/nate/soft/trilium/trilium-trans/trilium-linux-x64/resources/app/src/services/import/zip.js:355:18)
    at /home/nate/soft/trilium/trilium-trans/trilium-linux-x64/resources/app/src/services/import/zip.js:461:13
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
TypeError: Cannot read property 'startsWith' of undefined
    at Object.isStringNote (/home/nate/soft/trilium/trilium-trans/trilium-linux-x64/resources/app/src/services/utils.js:172:17)
    at Note.isStringNote (/home/nate/soft/trilium/trilium-trans/trilium-linux-x64/resources/app/src/becca/entities/note.js:301:22)
    at Note.setContent (/home/nate/soft/trilium/trilium-trans/trilium-linux-x64/resources/app/src/becca/entities/note.js:234:18)
    at saveNote (/home/nate/soft/trilium/trilium-trans/trilium-linux-x64/resources/app/src/services/import/zip.js:355:18)
    at /home/nate/soft/trilium/trilium-trans/trilium-linux-x64/resources/app/src/services/import/zip.js:461:13
    at processTicksAndRejections (internal/process/task_queues.js:93:5)

And only a partial of the demo notes is successfully imported. ksnip_20211214-143653

Additional Information

I remember I did this with 0.47 without error. I wonder if there is something changed in 0.48.

Nriver commented 2 years ago

I have tried to rebuild the zip with 7z, python, they all end up with error. Then I tried to use nodejs with archiver to mimic trilium

const archiver = require('archiver');
const file_system = require('fs');
const output = file_system.createWriteStream('demo-archiver.zip');

const archive = archiver('zip', {
    zlib: { level: 9 } // Sets the compression level.
});

output.on('close', function () {
    console.log(archive.pointer() + ' total bytes');
    console.log('archiver has been finalized and the output file descriptor has closed.');
});

archive.on('error', function(err){
    throw err;
});

archive.pipe(output);

// append files from a sub-directory, putting its contents at the root of archive
archive.directory('demo', false);

archive.finalize();

This gives me a zip file of the same size of the original built-in demo.zip. However the import still gives the error.

zadam commented 2 years ago

Hi, could you please attach the ZIP file so I can reproduce the issue locally?

Thanks.

Nriver commented 2 years ago

This is the original demo.zip demo_built-in.zip

This one is created by zip command. demo_zip.zip

This one is created by archiver module with the code above. demo_archiver.zip

zadam commented 2 years ago

Hi, thanks for the ZIP files, I could reproduce and fix the problem.

Re-ZIPped file changed the order of files in the ZIP which caused problems for cloned notes because the cloned note appeared in the listing before the "original" note.