From bcc343d9b295ada7006cfbc5a3bbcef78b261d9d Mon Sep 17 00:00:00 2001 From: Kirit Thadaka Date: Tue, 5 Dec 2017 04:14:51 +0530 Subject: [PATCH] Allowing non empty dirs to be deleted --- notebook/services/contents/filemanager.py | 13 ++----------- .../services/contents/tests/test_contents_api.py | 3 ++- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/notebook/services/contents/filemanager.py b/notebook/services/contents/filemanager.py index ef397d4e3..bd586ad1a 100644 --- a/notebook/services/contents/filemanager.py +++ b/notebook/services/contents/filemanager.py @@ -489,17 +489,8 @@ class FileContentsManager(FileManagerMixin, ContentsManager): path = path.strip('/') os_path = self._get_os_path(path) rm = os.unlink - if os.path.isdir(os_path): - listing = os.listdir(os_path) - # Don't delete non-empty directories. - # A directory containing only leftover checkpoints is - # considered empty. - cp_dir = getattr(self.checkpoints, 'checkpoint_dir', None) - for entry in listing: - if entry != cp_dir: - raise web.HTTPError(400, u'Directory %s not empty' % os_path) - elif not os.path.isfile(os_path): - raise web.HTTPError(404, u'File does not exist: %s' % os_path) + if not os.path.exists(os_path): + raise web.HTTPError(404, u'File or directory does not exist: %s' % os_path) if self.delete_to_trash: self.log.debug("Sending %s to trash", os_path) diff --git a/notebook/services/contents/tests/test_contents_api.py b/notebook/services/contents/tests/test_contents_api.py index 990b6ca51..9b880f539 100644 --- a/notebook/services/contents/tests/test_contents_api.py +++ b/notebook/services/contents/tests/test_contents_api.py @@ -518,7 +518,8 @@ class APITest(NotebookTestBase): for name in sorted(self.dirs + ['/'], key=len, reverse=True): listing = self.api.list(name).json()['content'] for model in listing: - self.api.delete(model['path']) + if os.path.exists(model['path']): + self.api.delete(model['path']) listing = self.api.list('/').json()['content'] self.assertEqual(listing, [])