sahib / rmlint

Extremely fast tool to remove duplicates and other lint from your filesystem
http://rmlint.rtfd.org
GNU General Public License v3.0
1.91k stars 132 forks source link

Glib json #480

Closed SeeSpotRun closed 3 years ago

SeeSpotRun commented 3 years ago

Note this PR was branched off earlier PR https://github.com/sahib/rmlint/pull/479 to simplify possible merging.

Should address #464 and #463 and make json handling more robust in future.

One side-effect of this implementation is that the json file doesn't get written until right at the end. The previous implementation writes to file as the results come in.

To do similar buffering with json-glib would require manually writing the opening and closing [ and ] to file, as well as the ,'s between array elements, and using a new JsonGenerator for each element. So it can be done but it's less elegant. But if we we run into problems keeping the JsonArray in memory then we might have to go that way anyway.

Thoughts @sahib ?

sahib commented 3 years ago

Hey @SeeSpotRun,

One side-effect of this implementation is that the json file doesn't get written until right at the end. The previous implementation writes to file as the results come in.

That's actually a crucial property for the following reasons:

So, yes, I think you should go with JsonGenerator. IIRC you don't need to instance a new one on each element, but can just call json_generator_set_root() on each (or so I hope to avoid the extra allocation).

SeeSpotRun commented 3 years ago

Yeah I kind of realised that as soon as I documented the PR. Oh well, less elegant but not the end of the world.