[arch-projects] [devtools] [PATCH] archbuild/makechrootpkg: Delete sub-subvolumes as well

Dave Reisner d at falconindy.com
Sat Jan 28 22:24:52 UTC 2017


On Sat, Jan 28, 2017 at 06:18:29PM +0100, Johannes Löthberg via arch-projects wrote:
> Some packages end up creating subvolumes through systemd-tmpfiles, (e.g.
> systemd-nspawn,) so we need to delete those as well.
> 
> Signed-off-by: Johannes Löthberg <johannes at kyriasis.com>
> ---
>  archbuild.in     | 10 +++++++++-
>  makechrootpkg.in |  5 +++++
>  2 files changed, 14 insertions(+), 1 deletion(-)
> 
> diff --git a/archbuild.in b/archbuild.in
> index 9c5d706..159602b 100644
> --- a/archbuild.in
> +++ b/archbuild.in
> @@ -54,7 +54,15 @@ if ${clean_first} || [[ ! -d "${chroots}/${repo}-${arch}" ]]; then
>  		lock 9 "$copy.lock" "Locking chroot copy '$copy'"
>  
>  		if [[ "$(stat -f -c %T "${copy}")" == btrfs ]]; then
> -			{ type -P btrfs && btrfs subvolume delete "${copy}"; } &>/dev/null
> +			# Delete all subvolumes under the copy directory.  This is needed
> +			# because some things, like systemd-nspawn, end up creating a btrfs
> +			# subvolume through systemd-tmpfiles.
> +			if type -P btrfs &>/dev/null; then
> +				btrfs subvolume list --sort=-path -o "$copy" | \
> +					sed 's|[^/]*||' | \
> +					xargs btrfs subvolume delete &>/dev/null

This isn't safe usage of xargs. You'd at least need to pass -d$'\n' in
order to delimit by newline. Couldn't you instead do something like:

  mapfile -t subvols < <(btrfs subvolume list ...)
  btrfs subvolume delete "${subvol[@]}" "$copy"

> +
> +				btrfs subvolume delete "$copy" &>/dev/null
> +			fi
>  		fi
>  		rm -rf --one-file-system "${copy}"
>  	done
> diff --git a/makechrootpkg.in b/makechrootpkg.in
> index 284d444..b89f33e 100644
> --- a/makechrootpkg.in
> +++ b/makechrootpkg.in
> @@ -91,6 +91,11 @@ create_chroot() {
>  		stat_busy "Creating clean working copy [$copy]"
>  		if [[ "$chroottype" == btrfs ]] && ! mountpoint -q "$copydir"; then
>  			if [[ -d $copydir ]]; then
> +				btrfs subvolume list --sort=-path -o "$copydir" | \
> +					sed 's|[^/]*||' | \
> +					xargs btrfs subvolume delete >/dev/null ||

same here.

> +						die "Unable to delete subvolumes under %s" "$copydir"
> +
>  				btrfs subvolume delete "$copydir" >/dev/null ||
>  					die "Unable to delete subvolume %s" "$copydir"
>  			fi
> -- 
> 2.11.0


More information about the arch-projects mailing list