Permalink
Browse files

Friendlier handling of attempt to remove root directory.

  • Loading branch information...
1 parent 9bf58a9 commit 8106286cf90c8a5ac0392146698fa047d8050530 @chrisrossi chrisrossi committed Nov 16, 2012
Showing with 13 additions and 0 deletions.
  1. +6 −0 acidfs/__init__.py
  2. +7 −0 acidfs/tests.py
View
@@ -326,6 +326,9 @@ def rmdir(self, path):
session = self._session()
parsed = self._mkpath(path)
+ if not parsed:
+ raise ValueError("Can't remove root directory.")
+
obj = session.find(parsed)
if not obj:
raise _NoSuchFileOrDirectory(path)
@@ -343,6 +346,9 @@ def rmtree(self, path):
session = self._session()
parsed = self._mkpath(path)
+ if not parsed:
+ raise ValueError("Can't remove root directory.")
+
obj = session.find(parsed)
if not obj:
raise _NoSuchFileOrDirectory(path)
View
@@ -381,6 +381,13 @@ def test_rmtree(self):
transaction.commit()
self.assertFalse(os.path.exists(path))
+ def test_cant_remove_root_dir(self):
+ fs = self.make_one()
+ with self.assertRaises(ValueError):
+ fs.rmdir('/')
+ with self.assertRaises(ValueError):
+ fs.rmtree('/')
+
def test_empty(self):
fs = self.make_one()
self.assertTrue(fs.empty('/'))

0 comments on commit 8106286

Please sign in to comment.