Patchwork [v2,2/2] populate_sdk_base: ensure that filenames with empty space character are handled

login
register
mail settings
Submitter João Henrique Freitas
Date July 14, 2014, 10:55 p.m.
Message ID <1405378518-4832-3-git-send-email-joaohf@gmail.com>
Download mbox | patch
Permalink /patch/75483/
State New
Headers show

Comments

João Henrique Freitas - July 14, 2014, 10:55 p.m.
When extracting toolchain, if the list $executable_files has filenames
with empty space character, the list will created but relocate_sdk.sh
will not handle it well. This will lead to the below erro:

    ./tmp/deploy/sdk/buildtools-mytools-x86_64-nativesdk-standalone-1.6.1.0.sh
    Enter target directory for SDK (default: /opt/mydistro/mytoolset/1.6.1.0):
    You are about to install the SDK to "/opt/mydistro/mytoolset/1.6.1.0". Proceed[Y/n]?
    Extracting SDK...done
    Setting it up.../opt/mydistro/mytoolset/1.6.1.0/relocate_sdk.sh: line 2: sintaxe error `token'  `('
    /opt/mydistro/mytoolset/1.6.1.0/relocate_sdk.sh: line 2: `e

The same occurs with replacement of ${SDKPATH} in configs/scripts/etc files.

We should ensure that full path is protected before relocate_sdk.sh
and ${SDKPATH} replacement calls.

Signed-off-by: João Henrique Ferreira de Freitas <joaohf@gmail.com>
---
 meta/classes/populate_sdk_base.bbclass | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Otavio Salvador - July 15, 2014, 1:33 p.m.
On Mon, Jul 14, 2014 at 7:55 PM, João Henrique Ferreira de Freitas
<joaohf@gmail.com> wrote:
> When extracting toolchain, if the list $executable_files has filenames
> with empty space character, the list will created but relocate_sdk.sh
> will not handle it well. This will lead to the below erro:
>
>     ./tmp/deploy/sdk/buildtools-mytools-x86_64-nativesdk-standalone-1.6.1.0.sh
>     Enter target directory for SDK (default: /opt/mydistro/mytoolset/1.6.1.0):
>     You are about to install the SDK to "/opt/mydistro/mytoolset/1.6.1.0". Proceed[Y/n]?
>     Extracting SDK...done
>     Setting it up.../opt/mydistro/mytoolset/1.6.1.0/relocate_sdk.sh: line 2: sintaxe error `token'  `('
>     /opt/mydistro/mytoolset/1.6.1.0/relocate_sdk.sh: line 2: `e
>
> The same occurs with replacement of ${SDKPATH} in configs/scripts/etc files.
>
> We should ensure that full path is protected before relocate_sdk.sh
> and ${SDKPATH} replacement calls.
>
> Signed-off-by: João Henrique Ferreira de Freitas <joaohf@gmail.com>

I am wondering if we cannot get rid of the 'tr' command that converts
newlines to '\0'. This would avoid a new fork of command. Did you
think about it?
João Henrique Freitas - July 16, 2014, 3:01 a.m.
Em 15-07-2014 10:33, Otavio Salvador escreveu:
> On Mon, Jul 14, 2014 at 7:55 PM, João Henrique Ferreira de Freitas
> <joaohf@gmail.com> wrote:
>> When extracting toolchain, if the list $executable_files has filenames
>> with empty space character, the list will created but relocate_sdk.sh
>> will not handle it well. This will lead to the below erro:
>>
>>      ./tmp/deploy/sdk/buildtools-mytools-x86_64-nativesdk-standalone-1.6.1.0.sh
>>      Enter target directory for SDK (default: /opt/mydistro/mytoolset/1.6.1.0):
>>      You are about to install the SDK to "/opt/mydistro/mytoolset/1.6.1.0". Proceed[Y/n]?
>>      Extracting SDK...done
>>      Setting it up.../opt/mydistro/mytoolset/1.6.1.0/relocate_sdk.sh: line 2: sintaxe error `token'  `('
>>      /opt/mydistro/mytoolset/1.6.1.0/relocate_sdk.sh: line 2: `e
>>
>> The same occurs with replacement of ${SDKPATH} in configs/scripts/etc files.
>>
>> We should ensure that full path is protected before relocate_sdk.sh
>> and ${SDKPATH} replacement calls.
>>
>> Signed-off-by: João Henrique Ferreira de Freitas <joaohf@gmail.com>
> I am wondering if we cannot get rid of the 'tr' command that converts
> newlines to '\0'. This would avoid a new fork of command. Did you
> think about it?
>
I think it's possible. Maybe  using: awk -F':' '{printf "%s\0", $1}' 
like this:

$SUDO_EXEC find $native_sysroot -type f -exec file '{}' \;|grep 
":.*\(ASCII\|script\|source\).*text"|awk -F':' '{printf "%s\0", 
$1}'|$SUDO_EXEC xargs -0 sed -i -e 
"s:$DEFAULT_INSTALL_DIR:$target_sdk_dir:g"

I will finish my tests before send a v3.

Thanks.

Patch

diff --git a/meta/classes/populate_sdk_base.bbclass b/meta/classes/populate_sdk_base.bbclass
index a12bf11..a6e23a1 100644
--- a/meta/classes/populate_sdk_base.bbclass
+++ b/meta/classes/populate_sdk_base.bbclass
@@ -252,7 +252,7 @@  if [ "$dl_path" = "" ] ; then
 	echo "SDK could not be set up. Relocate script unable to find ld-linux.so. Abort!"
 	exit 1
 fi
-executable_files=$($SUDO_EXEC find $native_sysroot -type f -perm /111)
+executable_files=$($SUDO_EXEC find $native_sysroot -type f -perm /111 -printf "'%h/%f' ")
 
 tdir=`mktemp -d`
 if [ x$tdir = x ] ; then
@@ -273,7 +273,7 @@  if [ $relocate = 1 ] ; then
 fi
 
 # replace ${SDKPATH} with the new prefix in all text files: configs/scripts/etc
-$SUDO_EXEC find $native_sysroot -type f -exec file '{}' \;|grep ":.*\(ASCII\|script\|source\).*text"|cut -d':' -f1|$SUDO_EXEC xargs sed -i -e "s:$DEFAULT_INSTALL_DIR:$target_sdk_dir:g"
+$SUDO_EXEC find $native_sysroot -type f -exec file '{}' \;|grep ":.*\(ASCII\|script\|source\).*text"|cut -d':' -f1|tr "\n" "\0"|$SUDO_EXEC xargs -0 sed -i -e "s:$DEFAULT_INSTALL_DIR:$target_sdk_dir:g"
 
 # change all symlinks pointing to ${SDKPATH}
 for l in $($SUDO_EXEC find $native_sysroot -type l); do