fix(image): clean partial mounts and refuse mounted export deletion
This commit is contained in:
+16
-6
@@ -58,6 +58,21 @@ sys.exit(code)
|
||||
'''
|
||||
|
||||
|
||||
def rootfs_retry_guard_script():
|
||||
"""Refuse deletion of a still-mounted export, including nested mountpoints."""
|
||||
return r"""mounts=$(findmnt --list --raw --noheadings --output TARGET)
|
||||
while IFS= read -r mountpoint; do
|
||||
case "$mountpoint" in
|
||||
"$root"|"$root/"*) echo 'Refusing to remove a mounted rootfs export' >&2; exit 1 ;;
|
||||
esac
|
||||
done <<< "$mounts"
|
||||
if [ -e "$root" ] || [ -L "$root" ]; then
|
||||
[ ! -L "$root" ] && [ -f "$root/.hydra-export-owned" ] || { echo 'Unowned rootfs output' >&2; exit 1; }
|
||||
rm -rf -- "$root"
|
||||
fi
|
||||
"""
|
||||
|
||||
|
||||
def verify_hash(path, expected):
|
||||
digest = hashlib.sha256()
|
||||
with Path(path).open('rb') as stream:
|
||||
@@ -421,12 +436,7 @@ fi'''
|
||||
snapshot = image.digest(original)
|
||||
assembler = self.assembly(snapshot)
|
||||
commit = self.run(['git', '-C', str(self.source_dir), 'rev-parse', 'HEAD'], capture=True).stdout.strip()
|
||||
script = r"""root=/hydra-output/rootfs
|
||||
if [ -e "$root" ] || [ -L "$root" ]; then
|
||||
[ ! -L "$root" ] && [ -f "$root/.hydra-export-owned" ] || { echo 'Unowned rootfs output' >&2; exit 1; }
|
||||
rm -rf -- "$root"
|
||||
fi
|
||||
mkdir -p "$root"
|
||||
script = 'root=/hydra-output/rootfs\n' + rootfs_retry_guard_script() + r"""mkdir -p "$root"
|
||||
touch "$root/.hydra-export-owned"
|
||||
tar --extract --preserve-permissions --numeric-owner --file /hydra-output/artifacts/builder-rootfs.tar --directory "$root"
|
||||
/hydra-source/image/configure-rootfs.sh "$root"
|
||||
|
||||
Reference in New Issue
Block a user