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
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions notebook/services/contents/filemanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import mimetypes
import nbformat

from send2trash import send2trash
from tornado import web

from .filecheckpoints import FileCheckpoints
Expand Down Expand Up @@ -144,6 +145,11 @@ def _validate_root_dir(self, proposal):
def _checkpoints_class_default(self):
return FileCheckpoints

delete_to_trash = Bool(True, config=True,
help="""If True (default), deleting files will send them to the
platform's trash/recycle bin, where they can be recovered. If False,
deleting files really deletes them.""")

def is_hidden(self, path):
"""Does the API style path correspond to a hidden directory or file?

Expand Down Expand Up @@ -464,6 +470,14 @@ def delete_file(self, path):
elif not os.path.isfile(os_path):
raise web.HTTPError(404, u'File does not exist: %s' % os_path)

if self.delete_to_trash:
self.log.debug("Sending %s to trash", os_path)
# Looking at the code in send2trash, I don't think the errors it
# raises let us distinguish permission errors from other errors in
# code. So for now, just let them all get logged as server errors.
send2trash(os_path)
return

if os.path.isdir(os_path):
self.log.debug("Removing directory %s", os_path)
with self.perm_to_403():
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@
'nbformat',
'nbconvert',
'ipykernel', # bless IPython kernel for now
'Send2Trash',
]
extras_require = {
':sys_platform != "win32"': ['terminado>=0.3.3'],
Expand Down