From aa948c5516ca99741cd217116df2b3573796fa57 2015-03-27 02:54:13 From: Scott Sanderson Date: 2015-03-27 02:54:13 Subject: [PATCH] BUG: Don't allow ContentsManager to delete root. Doing so leaves the notebook app in a bad state. --- diff --git a/IPython/html/services/contents/manager.py b/IPython/html/services/contents/manager.py index 3f2e2a2..a865ff4 100644 --- a/IPython/html/services/contents/manager.py +++ b/IPython/html/services/contents/manager.py @@ -222,6 +222,9 @@ class ContentsManager(LoggingConfigurable): def delete(self, path): """Delete a file/directory and any associated checkpoints.""" + path = path.strip('/') + if not path: + raise HTTPError(400, "Can't delete root") self.delete_file(path) self.checkpoints.delete_all_checkpoints(path) diff --git a/IPython/html/services/contents/tests/test_manager.py b/IPython/html/services/contents/tests/test_manager.py index 73bf522..6fa5a6d 100644 --- a/IPython/html/services/contents/tests/test_manager.py +++ b/IPython/html/services/contents/tests/test_manager.py @@ -433,6 +433,12 @@ class TestContentsManager(TestCase): # Check that a 'get' on the deleted notebook raises and error self.assertRaises(HTTPError, cm.get, path) + def test_delete_root(self): + cm = self.contents_manager + with self.assertRaises(HTTPError) as err: + cm.delete('') + self.assertEqual(err.exception.status_code, 400) + def test_copy(self): cm = self.contents_manager parent = u'å b'