Status quo
As you likely know I’m developing Syncthing Tray. Who has already tested it has likely noticed, that the following features do not work very well so far:
- Showing notifications when a directory has been synchronized, eg. “Synchronization of folder x complete”
- Detect when Syncthing really does nothing, eg. to shutdown after all local changes have been uploaded:
syncthingctl wait-for-idle --timeout 1800000 --at-least 5000 && systemctl poweroff
Why it doesn’t work
The idle detection simply checks whether the directory status is idle
.
To implement the notifications, I simply check for the status transition sync
⇨ idle
and emit the notification in that case.
Sounds like a simple and reasonable approach but there are two problems:
- A directory only has the status
sync
when it is pulling changes, but not when pushing. So whether files are (still) being uploaded can not really be determined. - Users of Syncthing Tray might have noticed that after uploading local changes a “Sync complete” notification is emitted nevertheless. However, I believe this is only the case because some index update is pulled back which causes the directory to be in status
sync
only for a short moment.
The behaviour described in 2. can even happen quite often during upload. This is very annoying when those notifications are enabled and likely the reason everybody turned them off in the settings. Eg. uploading an album produces a notification for each uploaded track.
Any false statements or misunderstandings on my side so far?
How to improve those features?
I think those features would be useful so I’d like to implement them properly. However, I’m not sure how to do it. The ideas and questions I’ve got so far:
-
Since the state
sync
only means downloading, is there some way to determine whether a directory is uploading? That would be quite useful. The eventsItemStarted
andItemFinished
are not useful here because they also only cover downloading if I understand correctly. -
Or maybe is there a way to find out whether each file/chunk/unit has at least been uploaded once?
That would actually be the required criteria because it would mean I can finally turn off the computer who “introduced” the new versions and the rest of the cluster can still become completely up-to-date on its own. So the “sync is complete” from the perspective of the particular node (which introduced the new versions).
Any other ideas how to improve the two features?