Skip to content
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

Sort the deleted files by date #3

Open
1nsp1r3rnzt opened this issue Apr 24, 2023 · 3 comments
Open

Sort the deleted files by date #3

1nsp1r3rnzt opened this issue Apr 24, 2023 · 3 comments
Labels
enhancement New feature or request

Comments

@1nsp1r3rnzt
Copy link

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
Copy link
Owner

proog commented Apr 24, 2023

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:

  • If a file is deleted outside of Obsidian (i.e. manually moved to .trash), the deletion date will be whenever the plugin next runs its detection logic
  • If a deleted file is restored and re-deleted outside of Obsidian (or a new file with the same name is moved to .trash), the plugin won't see that it's actually a new file, and will reuse the old deletion date

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 :)

@proog proog added the enhancement New feature or request label Apr 24, 2023
@1nsp1r3rnzt
Copy link
Author

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
Copy link
Owner

proog commented Jul 1, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants