wolpi / prim-ftpd

FTP server app for android
Other
580 stars 78 forks source link

Fix Android bug on FAT32 time resolution and mtime caching #360

Open lmagyar opened 3 weeks ago

lmagyar commented 3 weeks ago

As I wrote in https://github.com/wolpi/prim-ftpd/pull/351#issuecomment-2158001529, Android lies about the lastModifiedTime. Even the specs says, that if the time resolution is lower than what we ask, the next getLastModifiedTime will give back the "truncated" value, this is simply not true (tested on real phone, Android 9.0 and emulator). It gives back the truncated values only when he wants, usually hours later. This is an unpredictable nightmare.

This fix:

Maybe the default 1ms is overkill, in theory FTP has sub-second resolution, though we can modify StorageManagerUtil to return only 1000 vs 2000 ms, in this case no overload needed in SafSshFileSystemView to limit sub second resolution to the 1s resolution of sftp messages.

lmagyar commented 3 weeks ago

Not the latest logs, but some proof it works. Emulator:

getFilesystemTimeResolutionForSftp(content://com.android.externalstorage.documents/tree/17FB-0715...
  found mount point /mnt/media_rw/17FB-0715 with type vfat

Real FAT32 card:

getFilesystemTimeResolutionForSftp(content://com.android.externalstorage.documents/tree/80AB-022A...
  found mount point /mnt/media_rw/80AB-022A with type sdfat with option fs=vfat:32

The fs=exfat sample in the code comment is from a real exFAT 64GB card.

wolpi commented 1 week ago

I'm really looking forward to that merge script :smile:

lmagyar commented 1 week ago

I'm really looking forward to that merge script 😄

The Python sync? 😄 It is working, I've added remote management (start/stop, with Automate or HomeAssistant) for Tailscale, pFTPd, Termux/sshd services (the later for inotifywait, to catch the changes on the fly). I need a few hours net to finalize it on to a v0.1 quality level, though with a newborn and a relocation I hardly find time to sleep. 😨

I will work on the tech comments above on next week.

wolpi commented 1 week ago

Happy coding between moving boxes and with new born on arm :smile: