diff --git a/generate/container.py b/generate/container.py index 9b4bfa6..7d10a1e 100644 --- a/generate/container.py +++ b/generate/container.py @@ -63,12 +63,22 @@ class Volume: return None return [cls(key, value) for key, value in val.items()] + def is_host_volume(self) -> bool: + """Check if this Volume is a named or a host volume.""" + return self.name.startswith("/") or self.name.startswith(".") + def command(self) -> str: """Option for podman container create.""" return f"--volume {self.name}:{self.path}" def create(self) -> str: """Create volume, if it does not exist.""" + if self.is_host_volume(): + # A HOST-DIR starting with a slash or dot is interpreted as a + # directory or file on the host machine. Since the script should + # not modify things outside its own tree, i.e. + # /var/lib/containerctl, ignore it. + return "" cmd = f"# Create volume {self.name}\n" cmd += f"if ! podman volume exists '{self.name}' 2> /dev/null\n" cmd += "then\n" @@ -78,6 +88,9 @@ class Volume: def remove(self) -> str: """Remove volume if it exists.""" + if self.is_host_volume(): + # As with create, don't touch the host system + return "" cmd = f"# Remove volume {self.name}\n" cmd += f"if podman volume exists '{self.name}' 2> /dev/null\n" cmd += "then\n"