fix(oci): reject missing managed mount roots

This commit is contained in:
VAIO73
2026-10-19 12:53:34 +00:00
parent 3e9c9eb25d
commit 1511680a95
2 changed files with 16 additions and 6 deletions
-5
View File
@@ -84,10 +84,7 @@ def remove_empty_format_directories(rootfs, deployment, backed_only=True, target
if not paths:
return 0
flags = os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW
try:
root = os.open(rootfs, flags)
except FileNotFoundError:
return 0
removed = 0
try:
for path in paths:
@@ -98,8 +95,6 @@ def remove_empty_format_directories(rootfs, deployment, backed_only=True, target
os.close(current)
current = following
removed += int(remove_empty_at(current))
except FileNotFoundError:
continue
except OSError as error:
if error.errno in (errno.ELOOP, errno.ENOTDIR):
raise ValueError('Symbolic link or invalid managed volume path') from error
+15
View File
@@ -174,6 +174,21 @@ class FormatDirectoryTests(unittest.TestCase):
opened.assert_not_called()
def test_missing_rootfs_is_an_error_without_remove(self):
with tempfile.TemporaryDirectory() as tmp, patch.object(volumes.os, 'rmdir') as remove:
with self.assertRaises(FileNotFoundError):
volumes.remove_empty_format_directories(Path(tmp) / 'missing', {'mounts': [
{'container_path': '/config', 'type': 'managed-volume', 'backup': True}]})
remove.assert_not_called()
def test_missing_managed_mount_is_an_error_without_remove(self):
with tempfile.TemporaryDirectory() as tmp, patch.object(volumes.os, 'rmdir') as remove:
with self.assertRaises(FileNotFoundError):
volumes.remove_empty_format_directories(Path(tmp), {'mounts': [
{'container_path': '/missing', 'type': 'managed-volume', 'backup': True}]})
remove.assert_not_called()
class StartupContractTests(unittest.TestCase):
def setUp(self):
directory = tempfile.TemporaryDirectory(); self.addCleanup(directory.cleanup)