Skip to content

Commit

Permalink
fix replace_in_files for file names with spaces
Browse files Browse the repository at this point in the history
Define files variable as an array and quote it when accessing it to
support file names with spaces.

Signed-off-by: George Prekas <[email protected]>
  • Loading branch information
george-enf committed Jun 3, 2022
1 parent 9e70029 commit 9ab2571
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions foreign_cc/private/framework/toolchains/freebsd_commands.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ if [ -d "$1" ]; then
SAVEIFS=$IFS
IFS=$'\n'
# Find all real files. Symlinks are assumed to be relative to something within the directory we're seaching and thus ignored
local files=$(find -P -f "$1" \\( -type f -and \\( -name "*.pc" -or -name "*.la" -or -name "*-config" -or -name "*.mk" -or -name "*.cmake" \\) \\))
local files=($(find -P -f "$1" \\( -type f -and \\( -name "*.pc" -or -name "*.la" -or -name "*-config" -or -name "*.mk" -or -name "*.cmake" \\) \\)))
IFS=$SAVEIFS
for file in ${files[@]}; do
for file in ${files[@]+"${files[@]}"}; do
local backup=$(mktemp)
touch -r "${file}" "${backup}"
sed -i '' -e 's@'"$2"'@'"$3"'@g' "${file}"
Expand Down
4 changes: 2 additions & 2 deletions foreign_cc/private/framework/toolchains/linux_commands.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ if [ -d "$1" ]; then
SAVEIFS=$IFS
IFS=$'\n'
# Find all real files. Symlinks are assumed to be relative to something within the directory we're seaching and thus ignored
local files=$(find -P "$1" \\( -type f -and \\( -name "*.pc" -or -name "*.la" -or -name "*-config" -or -name "*.mk" -or -name "*.cmake" \\) \\))
local files=($(find -P "$1" \\( -type f -and \\( -name "*.pc" -or -name "*.la" -or -name "*-config" -or -name "*.mk" -or -name "*.cmake" \\) \\)))
IFS=$SAVEIFS
for file in ${files[@]}; do
for file in ${files[@]+"${files[@]}"}; do
local backup=$(mktemp)
touch -r "${file}" "${backup}"
sed -i 's@'"$2"'@'"$3"'@g' "${file}"
Expand Down
4 changes: 2 additions & 2 deletions foreign_cc/private/framework/toolchains/macos_commands.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ if [ -d "$1" ]; then
SAVEIFS=$IFS
IFS=$'\n'
# Find all real files. Symlinks are assumed to be relative to something within the directory we're seaching and thus ignored
local files=$(find -P -f "$1" \\( -type f -and \\( -name "*.pc" -or -name "*.la" -or -name "*-config" -or -name "*.mk" -or -name "*.cmake" \\) \\))
local files=($(find -P -f "$1" \\( -type f -and \\( -name "*.pc" -or -name "*.la" -or -name "*-config" -or -name "*.mk" -or -name "*.cmake" \\) \\)))
IFS=$SAVEIFS
for file in ${files[@]}; do
for file in ${files[@]+"${files[@]}"}; do
local backup=$(mktemp)
touch -r "${file}" "${backup}"
sed -i '' -e 's@'"$2"'@'"$3"'@g' "${file}"
Expand Down
4 changes: 2 additions & 2 deletions foreign_cc/private/framework/toolchains/windows_commands.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ if [ -d "$1" ]; then
SAVEIFS=$IFS
IFS=$'\n'
# Find all real files. Symlinks are assumed to be relative to something within the directory we're seaching and thus ignored
local files=$($REAL_FIND -P "$1" -type f \\( -type f -and \\( -name "*.pc" -or -name "*.la" -or -name "*-config" -or -name "*.mk" -or -name "*.cmake" \\) \\))
local files=($($REAL_FIND -P "$1" -type f \\( -type f -and \\( -name "*.pc" -or -name "*.la" -or -name "*-config" -or -name "*.mk" -or -name "*.cmake" \\) \\)))
IFS=$SAVEIFS
# Escape any backslashes so sed can understand what it's supposed to replace
local argv2=$(echo "$2" | sed 's/\\\\/\\\\\\\\/g')
local argv3=$(echo "$3" | sed 's/\\\\/\\\\\\\\/g')
for file in ${files[@]}; do
for file in ${files[@]+"${files[@]}"}; do
local backup=$(mktemp)
touch -r "${file}" "${backup}"
sed -i 's@'"${argv2}"'@'"${argv3}"'@g' "${file}"
Expand Down

0 comments on commit 9ab2571

Please sign in to comment.