proog / obsidian-trash-explorer

Restore and delete files from the Obsidian .trash folder
MIT License
32 stars 2 forks source link

Sort the deleted files by date #3

Open 1nsp1r3rnzt opened 1 year ago

1nsp1r3rnzt commented 1 year ago

I would love to see the ability to sort deleted files by date . This would be incredibly helpful for managing and organizing files within the plugin. The ideal outcome is to have the recently deleted files at the top of the list. It's useful to quickly restore an accidently deleted file.

Also, your plugin been an invaluable tool for me and I appreciate the effort you have put into creating and maintaining it.

proog commented 1 year ago

Thank you!

Being able to sort by deletion date would be a very useful feature indeed. Unfortunately, it's currently not possible to get the deletion date through Obsidian's file API, which makes the feature difficult to implement reliably. I'm gonna add a little background info here because this blocks implementing #2 as well.

Obsidian provides the "mtime" and "ctime" timestamps for each file. mtime means "modification time", which updates when the file contents are modified, but ctime is platform-dependent. On Linux/Mac it updates when the contents or attributes change, on Windows it's the creation time. Neither of these can reliably be used as a deletion date.

So we'll have to track deletion ourselves. One possible implementation would be something like:

  1. Create a data structure that associates file paths in .trash with a timestamp
  2. The first time a path is seen in .trash, add an entry with the path and the current time (effectively the deletion date)
  3. Remove entries when the path no longer exists in .trash to prevent newly deleted files from inheriting a deletion date from a previously deleted file with the same path
  4. Save the data structure as plugin data so it persists across Obsidian restarts

This would work as long as files are deleted from within Obsidian, but there are some cases that will produce an incorrect deletion date, for instance:

These scenarios are probably convoluted enough that the issues are acceptable, but it's important to acknowledge that Obsidian's vaults are supposed to be interoperable.

Additionally, Obsidian Sync won't sync the .trash folder, but synchronization tools like iCloud will, so the plugin needs to prevent two machines from overwriting each other's deletion dates. Either it will have to distinguish between sync providers (and reuse the deletion dates only when the .trash folder is synced) or disable reusing deletion dates from other machines entirely.

So there are a couple of challenges associated with this feature. If anyone wants to take a stab at implementing it or has ideas for a more reliable technique, let me know :)

1nsp1r3rnzt commented 1 year ago

Thanks for following up. I see Obsidian has API limitations. Also, it seems that the feature needs different implementation for each OS. For my use case, I thought another idea might be to provide search bar at the top so a user can filter the file they want to restore. They can search by file name in the shown files list which will easily help to find the deleted file. It's the next good enough solution I thought.

proog commented 1 year ago

Hi again, I just released a new version of the plugin that contains a search bar. I hope it's of use to you :)