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

Send files to OS trash mechanism on delete #1968

Merged
merged 2 commits into from Oct 20, 2017
Merged

Conversation

@takluyver
Copy link
Member

@takluyver takluyver commented Dec 12, 2016

This adds a config option, defaulting to use trash, and adds a dependency on the pure-Python 'send2trash' package. Linux, Mac and Windows should all be supported.

Alternatively, we could make it default to hard delete (the current behaviour), and let users opt in to trash behaviour. Then Send2Trash could be a soft dependency.

This doesn't touch the UI yet, so you still get a confirmation dialog which inaccurately says it will permanently delete' the file. If we want to do this, we'll need some way for the contents manager to pass
the UI a hint about whether deleting is permanent or not.

Closes gh-165

This adds a config option, defaulting to use trash, and adds a
dependency on the pure-Python 'send2trash' package. Linux, Mac and
Windows should all be supported.

Alternatively, we could make it default to hard delete (the current
behaviour), and let users opt in to trash behaviour. Then Send2Trash
could be a soft dependency.

This doesn't touch the UI yet, so you still get a confirmation dialog
which inaccurately says it will 'permanently delete' the file. If we
want to do this, we'll need some way for the contents manager to pass
the UI a hint about whether deleting is permanent or not.

Closes jupytergh-165
@gnestor gnestor added this to the 4.3.1 milestone Dec 13, 2016
@minrk minrk added this to the 5.0 milestone Dec 14, 2016
@minrk minrk removed this from the 4.3.1 milestone Dec 14, 2016
@minrk
Copy link
Member

@minrk minrk commented Jan 4, 2017

I think a lot of people would be happy about this, so I would say that it makes sense as a default. One case where this might not be sufficient is a hosted service where the notebook server is the only window on the system (e.g. JupyterHub, cloud services). In these cases, without a read API for the trash, you get something in the middle: lost access to files, but the data isn't actually cleaned up. But then again, trash is really something along the lines of a ~/.trash folder, so it's possible to dig around and find what you lost.

Loading

@takluyver
Copy link
Member Author

@takluyver takluyver commented Jan 19, 2017

This still seems like there's enough to work out that I'm bumping it to 5.1.

Loading

@takluyver
Copy link
Member Author

@takluyver takluyver commented Jul 3, 2017

5.1 is approaching, and there's still quite a bit of work to do. Bumping to backlog.

Loading

@takluyver takluyver added this to the Backlog milestone Jul 3, 2017
@takluyver takluyver removed this from the 5.1 milestone Jul 3, 2017
@gnestor
Copy link
Contributor

@gnestor gnestor commented Jul 27, 2017

@takluyver It would be great to ship this! What more needs to be done?

Loading

@takluyver
Copy link
Member Author

@takluyver takluyver commented Jul 27, 2017

To enable it by default, we'd need a way to get files back from the trash, I think. The major platforms have different trash mechanisms, so that's not straightforward.

To make it an off-by-default option, which offers much less benefit, we'd need a way for the frontend to know whether 'delete' is hard or soft, so that the UI can display appropriate information.

Loading

@takluyver
Copy link
Member Author

@takluyver takluyver commented Jul 27, 2017

Looking at some of the issues open on send2trash (arsenetar/send2trash#9, arsenetar/send2trash#2), and thinking a bit about the complexity of the operation in general, I suspect that this would be an ongoing source of problems which we have little ability to fix. I'm not sure whether that outweighs the benefits.

One option would be to define our own trash mechanism separate from the system recycle bin. But I suspect that there's a bunch of complexity we haven't thought about, with things like network filesystems, folders shared with VMs/containers, and folders synced by things like Dropbox. It would also be annoying for people who actually want to delete things if those things were neither deleted nor placed in the normal trash.

Loading

@gnestor
Copy link
Contributor

@gnestor gnestor commented Jul 27, 2017

I hear ya. It sounds like an elegant solution for the common user (because they can always recover the notebook from the trash) but I'm sue there are many edge cases where this fails.

Loading

minrk
minrk approved these changes Jul 31, 2017
@minrk
Copy link
Member

@minrk minrk commented Jul 31, 2017

👍 on trying this out in 5.1, for me.

Loading

@takluyver
Copy link
Member Author

@takluyver takluyver commented Jul 31, 2017

Do you think we should try to do UI changes for 5.1, or leave the UI as is, with no mention of trash?

Loading

@minrk
Copy link
Member

@minrk minrk commented Jul 31, 2017

Since there's a server-side flag and we have no UI of our own for recovering things from the trash, I think it's okay as-is for now.

Loading

@takluyver
Copy link
Member Author

@takluyver takluyver commented Jul 31, 2017

Travis failures are due to a bug in Send2Trash, fixed by arsenetar/send2trash#12 . I've asked for a new release there.

Loading

@gnestor gnestor mentioned this pull request Jul 31, 2017
11 tasks
@takluyver takluyver added this to the 5.1 milestone Jul 31, 2017
@takluyver takluyver removed this from the Backlog milestone Jul 31, 2017
@takluyver
Copy link
Member Author

@takluyver takluyver commented Jul 31, 2017

Optimistically tagged as 5.1 - we're waiting on a new release of send2trash before we can do this. If we're ready to release first, bump this to 5.2.

Loading

@takluyver
Copy link
Member Author

@takluyver takluyver commented Jul 31, 2017

There's a new release of send2trash - re-triggering tests.

Loading

@takluyver takluyver closed this Jul 31, 2017
@takluyver takluyver reopened this Jul 31, 2017
@takluyver
Copy link
Member Author

@takluyver takluyver commented Aug 8, 2017

Re-running tests with send2trash 1.4.1.

Loading

@takluyver takluyver closed this Aug 8, 2017
@takluyver takluyver reopened this Aug 8, 2017
@takluyver
Copy link
Member Author

@takluyver takluyver commented Aug 8, 2017

Tests are passing, but I think it's still best to merge this after the release, so we can test it in master for a while.

Loading

@takluyver
Copy link
Member Author

@takluyver takluyver commented Sep 15, 2017

5.1 is now out, if we want to come back to this. As a reminder, this PR currently:

  • Makes Send2Trash a hard dependency.
  • Adds a config option FileContentsManager.delete_to_trash.
    • False is the current behaviour (hard delete)
    • True (default) sends files to the platform trash location when you delete them through the contents API
  • Does not provide any way to restore trashed files or permanently delete them. Users will have to use their system UI for this.

Loading

@gnestor
Copy link
Contributor

@gnestor gnestor commented Sep 16, 2017

I just tested and it works for me on macOS 10.12.6. I think this is heaps better than permanently deleting files be default. I imagine it would be really painful to accidentally delete some important notebooks and files and not be able to recover them. It's much less painful to be required to go to the trash to permanently delete files.

I vote to merge!

Loading

@gnestor
Copy link
Contributor

@gnestor gnestor commented Oct 9, 2017

Would love to get this in 5.2, but I think it still requires a little more review/testing. Marking as 5.3 for now...

Loading

@gnestor gnestor removed this from the 5.2 milestone Oct 9, 2017
@gnestor gnestor added this to the 5.3 milestone Oct 9, 2017
@dsblank
Copy link
Member

@dsblank dsblank commented Oct 9, 2017

Imagine having a class of new users... please give us a countdown so that we can celebrate the coming of this feature :)

Loading

@takluyver
Copy link
Member Author

@takluyver takluyver commented Oct 10, 2017

I think the plan was to merge it just after 5.1 so it was in master for a while. We missed doing that, and we're releasing 5.2 sooner than expected, so I guess the new plan is to merge it soon after 5.2 so that it's in master for a while before 5.3.

Loading

@gnestor
Copy link
Contributor

@gnestor gnestor commented Oct 10, 2017

Roger that @takluyver!

Loading

@takluyver
Copy link
Member Author

@takluyver takluyver commented Oct 20, 2017

Ping @gnestor @minrk - still happy to try putting this in for 5.3?

Loading

@minrk minrk merged commit aa461d9 into jupyter:master Oct 20, 2017
4 checks passed
Loading
@minrk
Copy link
Member

@minrk minrk commented Oct 20, 2017

Let's do it!

Loading

@takluyver takluyver deleted the delete-to-trash branch Oct 20, 2017
@gnestor
Copy link
Contributor

@gnestor gnestor commented Oct 20, 2017

👏👏👏

Loading

@willingc
Copy link
Member

@willingc willingc commented Oct 21, 2017

Nice addition @takluyver. Small issue with the merged PR: it broke the RTD build :(

Loading

@takluyver
Copy link
Member Author

@takluyver takluyver commented Oct 21, 2017

Thanks Carol. I think #2964 should fix it.

Loading

@jt7williams
Copy link

@jt7williams jt7williams commented Aug 28, 2020

Hello, I have deleted a Jupyter notebook by accident. I was using the Hub interface through google chrome, is there a way for me to recover this file?

Loading

@kevin-bates
Copy link
Member

@kevin-bates kevin-bates commented Aug 28, 2020

Hmm. Can you describe the environment (configuration, operating system, etc.) in which Hub is running? Do you have access to the machine which was/is hosting your spawned Notebook server instance?

On Windows, I'm assuming the deleted file would reside in your RecycleBin, on MacOs in your Trash and, it looks like, on Unix a .Trash directory (see the links on the send2trash README). This functionality utilizes the send2trash package. There are some caveats listed on the repository's README. Here's a link to the notebook code in case that helps.

In the meantime, I'm copying @minrk since he would have insight on how this might behave across a Hub cluster - either single or multi-node and might also have other ideas.

I'm hoping your file is sitting in one of the aforementioned locations. Good luck.

Loading

@jt7williams
Copy link

@jt7williams jt7williams commented Aug 28, 2020

Hello, I don't have access to the server, it is the school's server, but it's okay tho, I just recoded the notebook. Thank you
very much.

Loading

@st-bender
Copy link

@st-bender st-bender commented Mar 2, 2021

This should never have been merged as it results in unexpected behaviour. It causes only trouble for no benefits. Make this a separate menu entry "move to trash" and not disguise it as "delete".

Loading

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 30, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

8 participants