-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix setLastModified() exception on SAF #351
Conversation
@@ -601,10 +601,6 @@ protected void process(Buffer buffer) throws IOException { | |||
} else { | |||
FileHandle fh = (FileHandle) p; | |||
fh.write(data, offset); | |||
SshFile sshFile = fh.getFile(); | |||
|
|||
sshFile.setLastModified(new Date().getTime()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it necessary to remove that?
When/where is setLastModified() invoked?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not necessary strictly, but slows down the copy, it calls this after each write block. Depending on the client (block size 4k-64k), 100 or 1000 times during each a file upload. :(
When invoked? In case of WinSCP:
- If I turn off "preserve timestamp", WinSCP calls only open/write/close, and the OS sets the last modified time.
- If I enable "preserve timestamp", it send a separate SSH_FXP_SETSTAT message, and that sets the timestamp.
- Tested with SAF and POFS (plain old FS) and reading the ftpd logs.
FYI: And now I've tested it with even directories, this works even on them! |
Ok, that sounds all good |
Many Thanks |
OMG. |
:) All credit goes to https://stackoverflow.com/users/15401262/usilo |
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. |
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_WRITEfixes #145
Tested on Android 9.0, Samsung A8