public inbox for isar-users@googlegroups.com
 help / color / mirror / Atom feed
From: Uladzimir Bely <ubely@ilbers.de>
To: isar-users@googlegroups.com
Subject: [PATCH] deb-dl-dir: Fallback to copying when import-export
Date: Tue, 31 Jan 2023 12:20:12 +0100	[thread overview]
Message-ID: <20230131112012.24054-1-ubely@ilbers.de> (raw)

By default, hardlinks are used when doing DL_DIR import and export.
This fails if DL_DIR's filesystem differs from TMPDIR's one.

Fallback to file copying (with lower performance and huge disk usage)
in this case.

Signed-off-by: Uladzimir Bely <ubely@ilbers.de>
---
 meta/classes/deb-dl-dir.bbclass | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/meta/classes/deb-dl-dir.bbclass b/meta/classes/deb-dl-dir.bbclass
index 7db25251..d572e6fb 100644
--- a/meta/classes/deb-dl-dir.bbclass
+++ b/meta/classes/deb-dl-dir.bbclass
@@ -80,13 +80,20 @@ deb_dl_dir_import() {
     export pc="${DEBDIR}/${2}"
     export rootfs="${1}"
     sudo mkdir -p "${rootfs}"/var/cache/apt/archives/
+
+    # Use hardlinks with fallback to `cp` if different filesystems
+    export cmd="ln -Pf -t"
+    if [ "$(stat -c %m ${pc})" != "$(stat -c %m ${rootfs})" ]; then
+        export cmd="cp -n --no-preserve=owner"
+    fi
+
     [ ! -d "${pc}" ] && return 0
     flock -s "${pc}".lock -c '
         set -e
         printenv | grep -q BB_VERBOSE_LOGS && set -x
 
         sudo find "${pc}" -type f -iname "*\.deb" -exec \
-            ln -Pf -t "${rootfs}"/var/cache/apt/archives/ {} +
+            ${cmd} "${rootfs}"/var/cache/apt/archives/ {} +
     '
 }
 
@@ -94,6 +101,13 @@ deb_dl_dir_export() {
     export pc="${DEBDIR}/${2}"
     export rootfs="${1}"
     mkdir -p "${pc}"
+
+    # Use hardlinks with fallback to `cp` if different filesystems
+    export cmd="ln -Pf"
+    if [ "$(stat -c %m ${pc})" != "$(stat -c %m ${rootfs})" ]; then
+        export cmd="cp -n"
+    fi
+
     flock "${pc}".lock -c '
         set -e
         printenv | grep -q BB_VERBOSE_LOGS && set -x
@@ -109,7 +123,7 @@ deb_dl_dir_export() {
             if [ -n "$package" ]; then
                 cmp --silent "$package" "$p" && continue
             fi
-            sudo ln -Pf "${p}" "${pc}"
+            sudo ${cmd} "${p}" "${pc}"
         done
         sudo chown -R $(id -u):$(id -g) "${pc}"
     '
-- 
2.20.1


             reply	other threads:[~2023-01-31 11:20 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-31 11:20 Uladzimir Bely [this message]
2023-02-01  9:00 ` Henning Schild
2023-02-01 14:27   ` Roberto A. Foglietta

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230131112012.24054-1-ubely@ilbers.de \
    --to=ubely@ilbers.de \
    --cc=isar-users@googlegroups.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox