objectstore: extract remove_tree()

Move remove_tree() into its own module in `osbuild.util.rmrf`. This way
we can use it in other modules as well, without cross-referencing
internal helpers.
This commit is contained in:
David Rheinsberg 2020-04-20 12:15:21 +02:00 committed by Tom Gundersen
parent 4ad4da4658
commit 2cc9160099
4 changed files with 152 additions and 77 deletions

View file

@ -2,25 +2,11 @@ import os
import shutil
import tempfile
import unittest
import subprocess
from pathlib import Path
from osbuild import objectstore
def can_set_immutable():
with tempfile.TemporaryDirectory(dir="/var/tmp") as tmp:
try:
os.makedirs(f"{tmp}/f")
# fist they give it ...
subprocess.run(["chattr", "+i", f"{tmp}/f"], check=True)
# ... then they take it away
subprocess.run(["chattr", "-i", f"{tmp}/f"], check=True)
except (subprocess.CalledProcessError, FileNotFoundError):
return False
return True
class TestObjectStore(unittest.TestCase):
@classmethod
@ -87,18 +73,6 @@ class TestObjectStore(unittest.TestCase):
# there should be no temporary Objects dirs anymore
self.assertEqual(len(os.listdir(object_store.tmp)), 0)
# pylint: disable=no-self-use
@unittest.skipUnless(can_set_immutable(), "Need root permissions")
def test_cleanup_immutable(self):
with tempfile.TemporaryDirectory(dir="/var/tmp") as tmp:
with objectstore.ObjectStore(tmp) as object_store:
tree = object_store.new()
with tree.write() as path:
p = Path(f"{path}/A")
p.touch()
subprocess.run(["chattr", "+i", f"{path}/A"],
check=True)
# pylint: disable=no-self-use
def test_duplicate(self):
with tempfile.TemporaryDirectory(dir="/var/tmp") as tmp: