-
Notifications
You must be signed in to change notification settings - Fork 138
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
feat(windows-trash): support for deleting to windows trash #243
Conversation
Thanks for showing some interest in helping with Windows! Yes, the freedesktop and mac adapters support deleting to trash, viewing the trash, restoring from trash, and purging from trash. They work slightly differently because the freedesktop implementation has information about where the deleted files were deleted from. On mac that information is encoded in a proprietary format so we basically just have a single "trash bin" folder where everything goes. The mac implementation is a lot simpler for this reason, but also less featureful. These adapters conform to the same structure as other adapters in oil Lines 13 to 26 in 636989b
Most likely the windows adapter will be more similar to mac than freedesktop, and it'll be easier to implement that way. So any One note: oil.nvim/lua/oil/adapters/files.lua Lines 268 to 271 in 636989b
|
I just added support for viewing, restoring and purging windows trash :3. The code is reaaaaaaaaally ugly right now and full of TODOs. Most of them are because of me not understanding if copying how the mac/freedesktop adapter works for certain things is ok ( Some of the TODOs are because I'm not sure about how should I handle the Do you maybe have some early feedback? Also, I'm unable to run the tests localy because, among other thigs, Edit: recentrly I learned to use |
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.
Making good progress! Left some comments. You'll also want to take the M.filter_action
from freedesktop. Do you happen to know if there are any uniqueness guarantees for the names of files? If you delete two files with the same name, how do they appear?
lua/oil/adapters/trash/windows.lua
Outdated
elseif action.type == "copy" then | ||
-- TODO: ... |
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.
Copy actions are a little weird for a trash adapter. Why would you want to restore a file but keep a copy in the trash? Why would you want to copy a file into the trash?
If Windows doesn't have a good way to perform these actions we can handle them differently. Maybe turn them into no-ops.
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.
I was scared of using the luv functions directly with files from the recycle bin (or the oil utiliy functions), so wanted to try if using regular poweshell operations worked first. It seems like using luv (and oil utility functions) directly does work to move/rename/delete this files, so I'll change that to (the windows adapter will end up looking a lot like the freedesktop one xd).
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.
Also, I found this random answer in stackoverflow about how recycle bin works on Windows. Would it be preffered to handle this in a low level way like in the freedesktop implementation? Given the lack of proper Windows documentation, I'm inclined to let poweshell send files to the recycle bin, but use a implementation similar to the freedesktop one for moving, coping and purging files (I'm now realizing that this would mean not only handling the deleted file itself, but also the file with the metadata, just like on freedesktop)
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.
I just pushed my last changes doing exactly this, let me know your thoughts on the matter. Powershell is still needed for listing recycle bin files and for sending files to the trash bin
For the metadata that I'm currently querying, this is the result for two files with the same name, deleted from the same location: [
{
"OriginalPath": "C:\\Users\\pcx\\Desktop\\a.txt",
"Name": "a.txt",
"ModifyDate": "2023-12-10T11:59:52",
"Path": "C:\\$Recycle.Bin\\S-1-5-21-2576758376-3460131066-3669222130-1001\\$RIZBAJN.txt",
"IsFolder": false
},
{
"OriginalPath": "C:\\Users\\pcx\\Desktop\\a.txt",
"Name": "a.txt",
"ModifyDate": "2023-12-10T11:59:59",
"Path": "C:\\$Recycle.Bin\\S-1-5-21-2576758376-3460131066-3669222130-1001\\$RXB3SZK.txt",
"IsFolder": false
}
] The |
Got it, so we'll want to handle this the same was as the freedesktop implementation. That means including this oil.nvim/lua/oil/adapters/trash/freedesktop.lua Lines 428 to 435 in a173b57
When you call In the metadata, set the |
Also, the parts of the code that use powershell are noticeably slower (I guess that spawning a powershell process for each operation may be expensive). I was thinking about having two background powershell proccesses always listening for input (this processes would be started either when the first command that needs them is executed or at startup), one for the What are your thoughts on this? |
Can't do a full review right now, but I'd say that unless it is unusably slow, I would lean towards making this PR focus on correct behavior over performance. It's easy enough to add those sorts of performance improvements later. |
Is there something this PR may be missing? If the performance can be improved in a following PR, I think this PR is behaving as expected |
I don't see anything obvious! I'm traveling and don't have my windows machine with me, but I'll test this out next year and see about merging it |
Tested it out and it seems to work! I see what you mean about the performance; it is a bit slow for some of the operations. I think this is great for a first revision and I'm happy to take additional changes to speed it up. Thanks for the contribution! |
This only adds support for
delete_to_trash
to the Windows trash adapter. I'm not sure about how the other adapters (freedesktop and mac) work, but at a glance I think they allow restoring files from trash, browsing files from trash, etc. Am I correct? I would like to help with the Windows trash adapter as much as I can, but I'm a bit lost.Thanks for the amazing pluging, by the way :3.