Allowing non empty dirs to be deleted

This commit is contained in:
Kirit Thadaka 2017-12-05 04:14:51 +05:30
parent b1e5f729fa
commit bcc343d9b2
2 changed files with 4 additions and 12 deletions

View File

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

View File

@ -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, [])