mirror of
https://github.com/jupyter/notebook.git
synced 2025-03-13 13:17:50 +08:00
Allowing non empty dirs to be deleted
This commit is contained in:
parent
b1e5f729fa
commit
bcc343d9b2
@ -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)
|
||||
|
@ -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, [])
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user