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

Conversation

takluyver
Copy link
Member

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 modified the milestones: 5.0, 4.3.1 Dec 14, 2016
@minrk
Copy link
Member

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.

@takluyver
Copy link
Member Author

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

@takluyver
Copy link
Member Author

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

@takluyver takluyver modified the milestones: Backlog, 5.1 Jul 3, 2017
@gnestor
Copy link
Contributor

gnestor commented Jul 27, 2017

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

@takluyver
Copy link
Member Author

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.

@takluyver
Copy link
Member Author

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.

@gnestor
Copy link
Contributor

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.

@minrk
Copy link
Member

minrk commented Jul 31, 2017

👍 on trying this out in 5.1, for me.

@takluyver
Copy link
Member Author

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

@minrk
Copy link
Member

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.

@takluyver
Copy link
Member Author

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

@gnestor gnestor mentioned this pull request Jul 31, 2017
11 tasks
@takluyver takluyver modified the milestones: 5.1, Backlog Jul 31, 2017
@takluyver
Copy link
Member Author

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.

@takluyver
Copy link
Member Author

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

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

Re-running tests with send2trash 1.4.1.

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

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.

@takluyver
Copy link
Member Author

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.

@gnestor
Copy link
Contributor

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!

@gnestor
Copy link
Contributor

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...

@gnestor gnestor modified the milestones: 5.2, 5.3 Oct 9, 2017
@dsblank
Copy link
Member

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

@takluyver
Copy link
Member Author

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.

@gnestor
Copy link
Contributor

gnestor commented Oct 10, 2017

Roger that @takluyver!

@takluyver
Copy link
Member Author

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

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

minrk commented Oct 20, 2017

Let's do it!

@takluyver takluyver deleted the delete-to-trash branch October 20, 2017 10:05
@gnestor
Copy link
Contributor

gnestor commented Oct 20, 2017

👏👏👏

@willingc
Copy link
Member

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

@takluyver
Copy link
Member Author

Thanks Carol. I think #2964 should fix it.

@jt7williams
Copy link

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?

@kevin-bates
Copy link
Member

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.

@jt7williams
Copy link

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.

@st-bender
Copy link

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".

@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
Development

Successfully merging this pull request may close these issues.

Safer ways of deleting notebooks - or undoing delete?
8 participants