: Adds `DIR` from the host as a new lower directory for the next overlayfs mount.
`--overlay-upperdir DIR`
-: Sets the upper directory for the next overlayfs mount to `DIR` from the host.
+: Sets the upper directory for the next overlayfs mount to `DIR` from the host. If
+ set to `tmpfs`, the upperdir and workdir will be subdirectories of a fresh tmpfs
+ mount.
`--overlay-workdir DIR`
: Sets the working directory for the next overlayfs mount to `DIR` from the host.
def execute(self, oldroot: str, newroot: str) -> None:
lowerdirs = tuple(chase(oldroot, p) for p in self.lowerdirs)
- upperdir = chase(oldroot, self.upperdir) if self.upperdir else None
+ upperdir = chase(oldroot, self.upperdir) if self.upperdir and self.upperdir != "tmpfs" else self.upperdir
workdir = chase(oldroot, self.workdir) if self.workdir else None
dst = chase(newroot, self.dst)
+
with umask(~0o755):
- os.makedirs(dst, exist_ok=True)
+ os.makedirs(os.path.dirname(dst), exist_ok=True)
+
+ mode = 0o1777 if any(dst.endswith(suffix) for suffix in ("/tmp", "/var/tmp")) else 0o755
+ if not os.path.exists(dst):
+ with umask(~mode):
+ os.mkdir(dst, mode=mode)
options = [
f"lowerdir={':'.join(lowerdirs)}",
"metacopy=off",
]
- if upperdir:
- options += [f"upperdir={upperdir}"]
- if workdir:
- options += [f"workdir={workdir}"]
+ if upperdir and upperdir == "tmpfs":
+ mount("tmpfs", dst, "tmpfs", 0, "mode=0755")
+
+ with umask(~mode):
+ os.mkdir(f"{dst}/upper", mode=mode)
+ with umask(~0o755):
+ os.mkdir(f"{dst}/work")
+
+ options += [f"upperdir={dst}/upper", f"workdir={dst}/work"]
+ else:
+ if upperdir:
+ options += [f"upperdir={upperdir}"]
+ if workdir:
+ options += [f"workdir={workdir}"]
mount("overlayfs", dst, "overlay", 0, ",".join(options))