+ $pre = <<'END_BOTH';
+ bld="$1"; shift; sd="$1"; shift; src="$1"; shift;
+ cd "$bld"; mkdir -p -- "$sd"; cd "$sd";
+END_BOTH
+ if ($oot_preclean ne 'no') {
+ $pre.= "find . -maxdepth 1 ! -path .";
+ $pre.= " ! -path ./target" if $oot_preclean ne 'full';
+ $pre.= " -print0 | xargs -0r rm -r --;"
+ }
+ if ($linkfarm_depth eq 'shallow') {
+ $pre.= <<'END_SHALLOW';
+ clean () { find -lname "$src/*" -print0 | xargs -0r rm --; }; clean;
+ find "$src" -maxdepth 1 \! -name Cargo.lock -print0 |
+ xargs -0r sh -ec 'for f in "$@"; do
+ rm -rf "${f##*/}";
+ ln -sf -- "$f" .;
+ done';
+END_SHALLOW
+ } elsif ($linkfarm_depth =~ /full|git/) {
+ $pre .= <<'END_EITHER_DEEP_DIRS';
+ clean () { find -follow -lname "$src/*" -print0 | xargs -0r rm --; };
+ (set -e; cd "$src"; find . \! -name Cargo.lock \! \( -name .git -prune \) \! -path . \! -name .git -type d -print0) |
+ xargs -0r sh -ec 'for f in "$@"; do
+ rm -f "$f" 2>/dev/null ||:;
+ mkdir -p "$f";
+ done' x;
+END_EITHER_DEEP_DIRS
+ if ($linkfarm_depth eq 'git') {
+ $pre .= <<'END_FILES_GIT'
+ (set -e; cd "$src"; git ls-files --exclude-standard -co -z) |
+END_FILES_GIT
+ } elsif ($linkfarm_depth eq 'full') {
+ $pre .= <<'END_FILES_FULL'
+ (set -e; cd "$src"; find . \! -name Cargo.lock \! \( -name .git -prune \) \! -type d -print0) |
+END_FILES_FULL
+ }
+ $pre .= <<'END_DEEP';
+ perl -0 -ne '
+ BEGIN { $src=shift @ARGV; }
+ next if (readlink "$_"//"") eq "$src/$_";
+ unlink "$_";
+ symlink "$src/$_", "$_" or die "$_ $!";
+ ' "$src";
+END_DEEP
+ } elsif ($linkfarm_depth =~ m/^copy-edit/) {
+ $pre .= <<'END_COPY_EDIT';
+ find -lname "$src/*" -print0 | xargs -0r rm --;
+ (set -e; cd "$src"; git ls-files -c -z |
+ cpio --quiet -p0m --no-preserve-owner -u --make-directories "$bld/$sd");
+ clean () {
+ (set -e; cd "$src"; git ls-files -c -z) | xargs -0r rm -f --;
+ };
+END_COPY_EDIT
+ if ($linkfarm_depth eq 'copy-edit-all') {
+ $post .= <<'END_COPY_EDIT_GENFILES_ALL';
+ find -xdev \( \( -name .git -o -path ./target -o -path ./nailing-cargo-update.tar \) -prune \) -o
+ \( -type l -o -type f \) -print0 |
+END_COPY_EDIT_GENFILES_ALL
+ } else {
+ $post .= <<'END_COPY_EDIT_GENFILES_GIT';
+ (set -e; cd "$src"; git ls-files -c -z) |
+END_COPY_EDIT_GENFILES_GIT
+ }
+ $post .= <<'END_COPY_EDIT_BUNDLE';
+ cpio -Hustar -o0 --quiet >"nailing-cargo-update.tar";
+END_COPY_EDIT_BUNDLE
+ } else {
+ die "$linkfarm_depth ?";
+ }
+ $pre .= <<'ENDLK' if $do_cargo_lock;
+ if test -e Cargo.lock; then
+ rm -f Cargo.lock;
+ cp -- "$src"/Cargo.lock .;
+ fi;