obsidian-api
obsidian-api copied to clipboard
any way to change mtime only?
Hi,
Is there any way to change mtime only? (which is similar to Linux's touch
command).
I found there are modify()
and modifyBinary()
. But the content (data
) must be provided, which means that though I could change the mtime by writing same content, it's very inefficient. I also tried to pass undefined
to data
but received no luck.
Another related issue is that the api also lacks the support of appending file
instead of rewriting file
. Is it also possible to do that?
Thank you so much!
btw, i am developing plugins for mobile obsidian, so nodejs fs module is not available……
I currently don't see a way to set mtime directly. What's your use case?
As for append, I'll look into it.
Hi,
I am developing a plugin about synchronizing notes (definitely NOT a replacement for the official solution but something meeting my personal needs).
The algorithm might involve comparing and/or setting the mtime of files and folders. (BTW, if possible, the ability of "appending file" besides "rewriting" might be extremely helpful.) But I dig into the current api, the only possible way is rewriting the file to reset the mtime.
Thank you for your reply. And Obsidian (mobile) is really great! 👍
Why do you need to write the mtime separately from writing the file? With Obsidian Sync, we store the mtime when a file syncs down with the write()
function. I'm not sure I understand in what case you would perform just a change to the mtime without also wanting to set the contents. (I guess if the file has "changed" but the content remained identical?)
Also what do you need append for in a synchronization situation?
For example, we want that a file has the same mtime in local and on remote. But after it is uploaded (synced) to the remote, the mtime of file on the remote are different from that in local (because uploading also takes time). We need to set the local mtime the same as the remote one. So we can identify the files that are absolutely different if their mtimes are different.
appending might be needed while something is being logged (or cached), which is usually appended only for most of the time
I will add append for the next insider release.
For example, we want that a file has the same mtime in local and on remote. But after it is uploaded (synced) to the remote, the mtime of file on the remote are different from that in local (because uploading also takes time). We need to set the local mtime the same as the remote one. So we can identify the files that are absolutely different if their mtimes are different.
I don't think this is a good way to solve the problem because it's a workaround for something else with possible consequences. Your remote host should be able to store mtimes based on the uploaded file. Your problem here is that if your sync solution wasn't running for a while, the moment it runs will change the modified time of any files that was edited during the downtime, which IMO isn't desired behavior - if I disconnect from sync for a year, then every note I modify during that year will have their mtime updated to now() when I reconnect to sync.
Obsidian Sync stores an additional "mtime" (and ctime) field in the server for the file. I'm guessing you can't because you're storing it directly in the file system - I'd propose figuring out a way to set the mtime on your remote server so the times match, instead of back-propagate the mtime from the server after upload.
if I disconnect from sync for a year, then every note I modify during that year will have their mtime updated to now() when I reconnect to sync.
In this situation, the local file is newer (by comparing mtimes) and should be synced to the remote.
I'm guessing you can't because you're storing it directly in the file system
Haha y are right! Something like FTP/webdav. I try to figure out a “clean” way now.
Yeah so if I understand it correctly it will end up with something like this:
- 2020-01-01 Disconnect sync
- 2020-06-01 Modify my file "note.md"
- 2020-12-01 Reconnect sync
- Uploads note.md
- Remote now says note.md modified on 2020-12-01 (because it was just uploaded)
- Update the local mtime to 2020-12-01 (because the times don't match)
- Original mtime is now lost
Is that correct?
Yes u are correct.
This should now be achiveable with append - just append nothing, and set the write options to overwrite the mtime.