From e157b808fbca4cd337ca537577e9de38c749ce0a Mon Sep 17 00:00:00 2001 From: CyberLeo Date: Fri, 6 May 2011 23:51:02 -0500 Subject: [PATCH] docs/spec, script/gentree: support whiteout list file --- docs/spec | 3 +++ script/gentree | 45 ++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/docs/spec b/docs/spec index 4506e6b..232d47a 100644 --- a/docs/spec +++ b/docs/spec @@ -64,6 +64,7 @@ targets/ conf/ - Confpack configuration: md_size files and previous save cpios overlay/ - A tree of files to be placed into the target filesystem prior to package installation patch/ - Patches applied to the target filesystem after all packages are installed + whiteout.lst - Any filenames that exist in here will be deleted; files with 'rm -f', directories with 'rm -rf' ports@ - Symlink to ports tree to use for build; assume /usr/ports if missing world@ - Symlink to the proper world against which this target is to be built log/ - Logfiles generated by build system go here @@ -73,3 +74,5 @@ targets/ tree/ - Directory for assembling final image Packages are built for a world, but specific to a target because they may have target-specific port_options or make.conf tweaks applied. + +Whiteout list files are simple lists, one pathspec per line, of target objects to delete after overlays, packages, and patches are applied. Each line should be relative to the root of the target filesystem image. The entry will be ignored if it resolves to a pathspec that does not exist within the target image. The entry will be ignored with a warning if it resolves to a path that falls outside of the target image's build directory (${sroot}), or if it points to a file contained within a non-directory object (such as /etc/fstab/none when /etc/fstab is not a directory) diff --git a/script/gentree b/script/gentree index 6f8494f..768e6b1 100755 --- a/script/gentree +++ b/script/gentree @@ -7,7 +7,7 @@ _root="$(dirname "${0}")" # Load needed modules want root ansi log ask -targets="prepwork admin overlay packages patch prepboot preptmp prepetc imgboot imgconf imgetc imgall custom" +targets="prepwork admin overlay packages patch whiteout prepboot preptmp prepetc imgboot imgconf imgetc imgall custom" pebkac() { [ "${*}" ] && printf "${*}\n\n" @@ -22,6 +22,7 @@ pebkac() { echo ' -o overlaydir Directory holding an overlay tree (${target}/config/overlay)' echo ' -i pkgsdir Directory holding packages to install (${target}/pkg)' echo ' -p patchdir Directory holding patches to apply (${target}/config/patch)' + echo ' -w whiteout Listfile of paths to remove (${target}/config/whiteout.lst)' echo ' -d confdir Conf md_size files and old cpios (${target}/config/conf)' echo ' -l logfile File to hold stderr spam (${stage}/gentree.log' echo ' -h Hello! >^-^<' @@ -45,6 +46,7 @@ do o) ovly="${OPTARG}" ;; i) pkgs="${OPTARG}" ;; p) ptch="${OPTARG}" ;; + w) rmrf="${OPTARG}" ;; d) cnfd="${OPTARG}" ;; l) logf="${OPTARG}" ;; h) pebkac ;; @@ -68,6 +70,7 @@ root="${root:-${target}/world/root}" ovly="${ovly:-${target}/config/overlay}" pkgs="${pkgs:-${target}/pkg}" ptch="${ptch:-${target}/config/patch}" +rmrf="${rmrf:-${target}/config/whiteout.lst}" cnfd="${cnfd:-${target}/config/conf}" logf="${logf:-${tree}/gentree.log}" @@ -156,6 +159,46 @@ do_patch() { done } +do_whiteout() { + [ -f "${rmrf}" ] || return + log Whiteout files from "${rmrf##${base}/}" + while read entry < "${rmrf}" + do + # Strip off terminating slash + entry="${entry%%/}" + # Obtain directory name, for path resolution + entry_path="$(dirname "${entry}")" + entry_path="$(realpath "${sroot}/${entry_path}" 2>/dev/null)" + entry_file="$(basename "${entry}")" + + # Ignore paths that do not exist + [ "${entry_path}" ] || continue + + # Warn and ignore paths that fall outside ${sroot} after resolution + if [ "$(echo ${entry_path} | sed -e "s/^\(.\{${#sroot}\}\).*$/\1/")" != "${sroot}" ] + then + warn "Whiteout '${entry}' malformed: leads outside '${sroot}'" + continue + fi + + # Warn and ignore paths that cannot be chdir()'d + if [ ! -d "${entry_path}" ] + then + warn "Whiteout '${entry}' malformed: non-directory in path" + continue + fi + + ( cd "${entry_path}" + if [ -d "${entry}" ] + then + echo rm -Rf "${entry}" + else + echo rm -f "${entry}" + fi + ) + done +} + do_prepboot() { log Prepare /boot chk mv "${sroot}/boot/boot" "${sroot}/boot/boot.blk" -- 2.42.0