diff mbox series

[1/1] Avoid running whilst in a deleted directory.

Message ID 20251102200653.3438957-1-gordon.lack@dsl.pipex.com
State New
Headers show
Series [1/1] Avoid running whilst in a deleted directory. | expand

Commit Message

Gordon Lack Nov. 2, 2025, 8:06 p.m. UTC
This caused a problem when building on Kubuntu 25.10.

Whilst the real problem is the cp in Rust coreutils, it makes sense not
to be in the directory you are about to delete.

---
 meta/recipes-devtools/perl/perl_5.40.2.bb | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Richard Purdie Nov. 2, 2025, 11:22 p.m. UTC | #1
On Sun, 2025-11-02 at 20:06 +0000, Gordon Lack via lists.openembedded.org wrote:
> 
> This caused a problem when building on Kubuntu 25.10.
> 
> Whilst the real problem is the cp in Rust coreutils, it makes sense not
> to be in the directory you are about to delete.
> 
> ---
>  meta/recipes-devtools/perl/perl_5.40.2.bb | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/meta/recipes-devtools/perl/perl_5.40.2.bb b/meta/recipes-devtools/perl/perl_5.40.2.bb
> index a78d2ed0be..ee6896b479 100644
> --- a/meta/recipes-devtools/perl/perl_5.40.2.bb
> +++ b/meta/recipes-devtools/perl/perl_5.40.2.bb
> @@ -58,6 +58,12 @@ CFLAGS:append:toolchain-clang = " -fno-strict-aliasing"
>  CFLAGS:append:toolchain-gcc:class-target:x86-64 = " -fno-builtin-memcpy -D__NO_STRING_INLINES -U_FORTIFY_SOURCE"
>  
>  do_configure:prepend() {
> +# ${B} will have been set as our current directory before immediately
> +# before do_configure is called. So let's avoid any problems associated
> +# with it being deleted from underneath us.
> +# We're being put back there (the new version) at the end of this code
> +#
> +    cd /
>      rm -rf ${B}
>      cp -rfp ${S} ${B}
>      cp -rfp ${STAGING_DATADIR_NATIVE}/perl-cross/* ${B}

Thanks for sending this! 

The patch does need a few small tweaks. I'd suggest "cd ${WORKDIR}" as
I get nervous about going to / and running rm, I appreciate it
shouldn't matter. I've not looked but I'd also like to confirm this
does a "cd ${B}" at the end so the cwd is restored?

The comments should also really be indented too to match the cd, just
for readability/coding style.

Cheers,

Richard
Gordon Lack Nov. 3, 2025, 12:57 a.m. UTC | #2
On 02/11/2025 23:22, Richard Purdie wrote:
> On Sun, 2025-11-02 at 20:06 +0000, Gordon Lack via lists.openembedded.org wrote:
>> This caused a problem when building on Kubuntu 25.10.
>>
>> Whilst the real problem is the cp in Rust coreutils, it makes sense not
>> to be in the directory you are about to delete.
>>
>> ---
>>   meta/recipes-devtools/perl/perl_5.40.2.bb | 6 ++++++
>>   1 file changed, 6 insertions(+)
>>
>> diff --git a/meta/recipes-devtools/perl/perl_5.40.2.bb b/meta/recipes-devtools/perl/perl_5.40.2.bb
>> index a78d2ed0be..ee6896b479 100644
>> --- a/meta/recipes-devtools/perl/perl_5.40.2.bb
>> +++ b/meta/recipes-devtools/perl/perl_5.40.2.bb
>> @@ -58,6 +58,12 @@ CFLAGS:append:toolchain-clang = " -fno-strict-aliasing"
>>   CFLAGS:append:toolchain-gcc:class-target:x86-64 = " -fno-builtin-memcpy -D__NO_STRING_INLINES -U_FORTIFY_SOURCE"
>>   
>>   do_configure:prepend() {
>> +# ${B} will have been set as our current directory before immediately
>> +# before do_configure is called. So let's avoid any problems associated
>> +# with it being deleted from underneath us.
>> +# We're being put back there (the new version) at the end of this code
>> +#
>> +    cd /
>>       rm -rf ${B}
>>       cp -rfp ${S} ${B}
>>       cp -rfp ${STAGING_DATADIR_NATIVE}/perl-cross/* ${B}
> Thanks for sending this!
>
> The patch does need a few small tweaks. I'd suggest "cd ${WORKDIR}" as
> I get nervous about going to / and running rm,
OK. But “cd /” never bothers me, as:

  * you can’t run a build as root (at least not the OE-alliance build I
    once tried as root on a old, spare, system in an attempt to debug
    something)
  * it’s the only location you can guarantee to be present.

>   I appreciate it
> shouldn't matter. I've not looked but I'd also like to confirm this
> does a "cd ${B}" at the end so the cwd is restored?
It does. One more context line would show it.

The full function is:

do_configure:prepend() {
# ${B} will have been set as our current directory before immediately
# before do_configure is called. So let's avoid any problems associated
# with it being deleted from underneath us.
# We're being put back there (the new version) at the end of this code
#
     cd /
     rm -rf ${B}
     cp -rfp ${S} ${B}
     cp -rfp ${STAGING_DATADIR_NATIVE}/perl-cross/* ${B}
     cd ${B}
}

> The comments should also really be indented too to match the cd, just
> for readability/coding style.
On the /readability/ we’ll have to differ.
Comments are *not* code, so indenting them to the same level makes 
/both/ unreadable.

With most code indented (in functions) and comments starting on column 1 
I can read each separately.
With both aligned the same I can’t see which is which.

I’ll submit a new patch that uses WORKDIR (it’s one level above ${B}, so 
will also work) and put all of the comments outside of the function, to 
make them readable.
diff mbox series

Patch

diff --git a/meta/recipes-devtools/perl/perl_5.40.2.bb b/meta/recipes-devtools/perl/perl_5.40.2.bb
index a78d2ed0be..ee6896b479 100644
--- a/meta/recipes-devtools/perl/perl_5.40.2.bb
+++ b/meta/recipes-devtools/perl/perl_5.40.2.bb
@@ -58,6 +58,12 @@  CFLAGS:append:toolchain-clang = " -fno-strict-aliasing"
 CFLAGS:append:toolchain-gcc:class-target:x86-64 = " -fno-builtin-memcpy -D__NO_STRING_INLINES -U_FORTIFY_SOURCE"
 
 do_configure:prepend() {
+# ${B} will have been set as our current directory before immediately
+# before do_configure is called. So let's avoid any problems associated
+# with it being deleted from underneath us.
+# We're being put back there (the new version) at the end of this code
+#
+    cd /
     rm -rf ${B}
     cp -rfp ${S} ${B}
     cp -rfp ${STAGING_DATADIR_NATIVE}/perl-cross/* ${B}