mtotschnig / MyExpenses

GPL licenced Android Expense Tracking App
http://www.myexpenses.mobi/
GNU General Public License v3.0
805 stars 217 forks source link

Synchronisation with SAF backend via Syncthing not working #1365

Open lord-aerion opened 8 months ago

lord-aerion commented 8 months ago

I can't get syncrhonisation via Syncthing working. Here are the steps I followed:

The 'Synchronization backends' screen now shows an entry named 'SAF - Expenses (com.android.externalstorage.documents), but expanding this entry does not show any accounts for synchronisation, and no files get created in the designated folder. Forcing a manual sync, either through the backend screen or via the 'Sync now' option in the main menu also does not create any files.

In addition, the backup option 'Store on synchronization backend' also does not create copies of the backup in the designated folder.

To clarify, the folder used by Syncthing to sync the My Expenses data is located on the internal storage, since Syncthing does not work with folders stored on external SD cards.

The issue, however is not related to Syncthing itself, since the designated folder itself syncs fine to my other devices, albeit empty as My Expenses doesn't create any files in this folder.

I'd really like this to work, as my partner and I are currently travelling through Ethiopia for 10 weeks, and we'd love the ability to manage our expenses on both our devices, as well as having a crude form of backup of our expenses should something happen to one of our devices.

For completeness sake, I'm using v3.7.1.1 from F-Droid, on Android 12.

What could be the issue here?

mtotschnig commented 7 months ago

@lord-aerion Thank you for reporting the issue, please excuse the late reply. Could you activate debug logging and share the log files as described here: https://github.com/mtotschnig/MyExpenses/wiki/FAQ%3A-Synchronization#synchronization-stopped-working-how-can-i-find-out-why .

lord-aerion commented 7 months ago

Sadly I'm no longer able to provide logs as, Sod's law, I lost my phone the day of your response, and with that all the expenses data from our trip up until that day 😭.

All I can add is that I did some further research while waiting for a response, and found your FAQ entry about syncing not working on Xiaomi devices unless Autostart has been enabled.

I tried this on my (now lost) Realme 7 Pro, and this indeed appeared to solve the issue at first. I got all the accounts synced to my partner's phone, and then it stopped working, i.e., nothing synced anymore past January 13 (the date I enabled Autostart for My Expenses). Autostart was still enabled, and neither restarting the phone nor disabling and reenabling Autostart solved it.

I removed all the accounts from my partner's phone, deleted the SAF backend and sync data on both phones, added a new SAF backend on both phones, and yet sync refused to work again with the same symptoms as described in my original post. All this time Autostart was left enabled on my Realme.

I'm now using My Expenses on my old backup phone (which thankfully I brought with me!), and while SAF based synchronisation via Syncthing now works between our two phones, I'm encountering issues with some items not syncing across, leading to incomplete data on both sides. As this is not related to this particular issue, I will try to figure this out and create a new issue if necessary.

Sorry I can't provide any further information or logs. I hope that at least the description above aprovides some more insight on what appears to be related to the Xiaomi issue!

mtotschnig commented 7 months ago

@lord-aerion Thank you very much for the elaborate feedback! It is now a documented problem that synchronization via SyncThing will easily break with the current implementation: #1390 (Problem 2). In a nutshell, with Syncthing there is no guarantee that the two devices do not write the same file to the same folder, whereas the current implementation relies on the idea of locking a folder to prevent that from happening. So I suppose that it should work as long as you make sure, that whenever a change happens on one device, it gets synced to the second device, before the second device records a change.