Mercurial > hg > aboriginal
changeset 903:5ffc758bf60a
Genericize search path traversal logic with pattern and command to apply to each file found.
author | Rob Landley <rob@landley.net> |
---|---|
date | Thu, 26 Nov 2009 02:37:36 -0600 |
parents | ab47c4944591 |
children | 2ed667428dbd |
files | sources/functions.sh sources/more/record-commands.sh |
diffstat | 2 files changed, 9 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- 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 }
--- 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