I don’t always have a perfect internet connection for multiple reasons (German trains, device is off, Wifi is disabled on the E-Reader to save power), so I used to have a lot of conflicts when using Syncthing, which I found super annoying, because often it would look like a data loss (it’s better now that conflict files are shown in Logseq itself, but still annoying) - all the stuff I had written on the train would just be gone.
So I built a little script based on Automatically resolve Syncthing conflicts using a three-way merge · Rafael Epplée that automatically detects conflicts and merges the corresponding files.
Finally no more .sync-conflict files scattered around the place! Since the sync-conflict files are just normal files that are synced, the conflict resolution can be done on one device and is synced over automatically. I have been stress testing it a little and it has held up very well.
There are a few assumptions:
Git is installed on the machine the script runs on
Versioning is enabled (I use staggered versioning)
The script is running inside the (base of) the Logseq folder
Now instead of sync conflicts/apparent data loss, the worst thing you’ll get is duplicated nodes.
While I’m using Logseq Sync on the moment, this looks like a perfect solve on my original syncthing setup, where I wasted so much time resolving stupid conflicts. (Like 2 empty files stupid)
Add it to my notes to try when another conflict draws me back to syncthing
Oh well that’s silly. I updated the post to actually include the script (lol, thanks for pointing out it’s missing).
As for reliability: It has been running on my server since I first made it a few weeks ago and it has been working perfectly well. The relief is immense, this used to be a big issue and I’m glad that it’s gone.
Since I have Syncthing on my server in a container, I made another one for this script and stuck it into the same docker-compose setup. Works well!
It runs constantly on my server, which also functions as a syncthing node. I use a container and docker-compose because I also run syncthing that way, but you could also use a systemd unit.
As a brittle but very simple way you could go the nohup/disown route, the main disadvantage being that you have to re-run it after every restart (definitely not recommended, but I ran Minecraft servers like this for quite a while).
Here’s my Dockerfile:
FROM alpine:latest
RUN apk add python3 py3-pip git
RUN pip install watchdog
WORKDIR /data
CMD ["sh", "-c", "ls -lah / && echo hi && python3 deconflicter.py"]
The sh-dance at the bottom is probably not necessary, but I used it for debugging and haven’t tested it without it.
Then in my docker-compose.yaml I mount the directory I want to deconflict to /data in the container:
Theoretically you could run the script on your main computer (or phone if you’re really crazy), but then it has to be on whenever you want to resolve a conflict.