# HG changeset patch # User Rob Landley # Date 1259224656 21600 # Node ID 5ffc758bf60aa9dafc9afdb8b7283eed5bf68c89 # Parent ab47c49445911a3cb52b2445d308138dd646c90c Genericize search path traversal logic with pattern and command to apply to each file found. diff -r ab47c4944591 -r 5ffc758bf60a sources/functions.sh --- a/sources/functions.sh Wed Nov 25 21:58:16 2009 -0600 +++ b/sources/functions.sh Thu Nov 26 02:37:36 2009 -0600 @@ -686,32 +686,27 @@ } -# Create a directory of symlinks to all binaries in a colon-separated path. +# Search a colon-separated path for files matching a pattern. -# Arguments are path to search, directory to populate, and (optionally) -# wrapper binary to symlink to instead of original binaries. +# Arguments are 1) path to search, 2) pattern, 3) command to run on each file. +# During command, $DIR/$FILE points to file found. -wrap_path() +path_search() { # For each each $PATH element, loop through each file in that directory, # and create a symlink to the wrapper with that name. In the case of # duplicates, keep the first one. - echo "$1" | sed 's/:/\n/g' | while read i + echo "$1" | sed 's/:/\n/g' | while read DIR do - ls -1 "$i" | while read j + find "$DIR" -maxdepth 1 -mindepth 1 | sed 's@.*/@@' | while read FILE do - if [ ! -z "$3" ] - then - ln -s "$3" "$2/$j" 2>/dev/null - else - ln -s "$i/$j" "$2/$j" 2>/dev/null - fi + eval "$3" # Output is verbose. Pipe it to dotprogress. - echo $j + echo $FILE done done } diff -r ab47c4944591 -r 5ffc758bf60a sources/more/record-commands.sh --- a/sources/more/record-commands.sh Wed Nov 25 21:58:16 2009 -0600 +++ b/sources/more/record-commands.sh Thu Nov 26 02:37:36 2009 -0600 @@ -10,9 +10,6 @@ echo "=== Setting up command recording wrapper" -echo OLDPATH=$OLDPATH -echo PATH=$PATH - [ -f "$WRAPDIR/wrappy" ] && PATH="$OLDPATH" [ -f "$HOSTTOOLS/busybox" ] && PATH="$HOSTTOOLS" blank_tempdir "$WRAPDIR" @@ -20,7 +17,7 @@ # Populate a directory of symlinks with every command in the $PATH. -wrap_path "$PATH" "$WRAPDIR" wrappy | dotprogress +path_search "$PATH" "*" 'ln -s wrappy "$WRAPDIR/$FILE"' | dotprogress # Build the wrapper $CC -Os "$SOURCES/toys/wrappy.c" -o "$WRAPDIR/wrappy" || dienow