Skip to contentSkip to conversation

Avoid running whilst in a deleted directory.

PATCH In review Gordon Lack 2 participants 3 messages Nov 2, 2025 – Nov 3, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Avoid running whilst in a deleted directory.

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(+)
meta/recipes-devtools/perl/perl_5.40.2.bb +6 -0
index a78d2ed0be..ee6896b479 100644
@@ -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}
Signature · 1 line
2.51.0
#1 lore raw
Quoted 24 lines · Gordon Lack via lists.openembedded.org

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(+)
meta/recipes-devtools/perl/perl_5.40.2.bb +0 -0
index a78d2ed0be..ee6896b479 100644
@@ -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() {

meta/recipes-devtools/perl/perl_5.40.2.bb +6 -0
+# ${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 /
Quoted 3 lines

     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

#2 lore raw
Quoted 29 lines · Richard Purdie
Quoted 16 lines · Gordon Lack via lists.openembedded.org

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(+)
meta/recipes-devtools/perl/perl_5.40.2.bb +0 -0
index a78d2ed0be..ee6896b479 100644
@@ -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"
 

meta/recipes-devtools/perl/perl_5.40.2.bb CFLAGS:append:toolchain-clang = " -fno-strict-aliasing" · line 69

Quoted 10 lines
meta/recipes-devtools/perl/perl_5.40.2.bb +6 -0
  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!

Quoted 2 lines

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.

Quoted 3 lines

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}
}
Quoted 2 lines

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.