wolpi / prim-ftpd

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

Fix setLastModified() exception on SAF #351

Closed lmagyar closed 3 weeks ago

lmagyar commented 1 month ago

In theory it is not possible: DocumentsContract.Document.COLUMN_LAST_MODIFIED is read-only.

In reality it is possible: we can't write the SD card's files with the file API, but we can set the attributes with the file API (what we can't through SAF, "great" design).

The solution is a copy-paste from https://stackoverflow.com/questions/63495498/android-scoped-storage-getcontentresolver-update-column-last-modified/66681306#66681306

Note: I also removed the sshFile.setLastModified(new Date().getTime()); call in each SSH_FXP_WRITE

fixes #145

Tested on Android 9.0, Samsung A8

lmagyar commented 1 month ago

FYI: And now I've tested it with even directories, this works even on them!

wolpi commented 3 weeks ago

Ok, that sounds all good

wolpi commented 3 weeks ago

Many Thanks

catscarlet commented 3 weeks ago

OMG. 6 years.

lmagyar commented 3 weeks ago

OMG. 6 years.

:) All credit goes to https://stackoverflow.com/users/15401262/usilo

lmagyar commented 3 weeks ago

One strange issue, seems to be an Android bug:

So it seems Android caches this mtime info, though the backing FAT32 FS stores only even-integer truncated values. When the cache is deleted and values are read from the real FS, timestamp magically changes...

This made me mad, I'm trying to create a bidirectional sync script, and even if I read back the "real" timestamp with STAT after SETSTAT, files started to change "randomly" during the night. They got 1 second older. Only the ones, that were odd-something seconds old on the previous day...

Android, what a mess...

Now I'm investigating where to put the workaround, in the ftpd server or in the sync script, I have to find a way to determine the filesystem's mtime resolution.