From mboxrd@z Thu Jan 1 00:00:00 1970 X-GM-THRID: 7197029299818332160 X-Received: by 2002:a05:6512:21b1:b0:4b1:7c15:e922 with SMTP id c17-20020a05651221b100b004b17c15e922mr2551798lft.214.1676027354371; Fri, 10 Feb 2023 03:09:14 -0800 (PST) X-BeenThere: isar-users@googlegroups.com Received: by 2002:a2e:a178:0:b0:293:32ba:16c6 with SMTP id u24-20020a2ea178000000b0029332ba16c6ls699220ljl.3.-pod-prod-gmail; Fri, 10 Feb 2023 03:09:12 -0800 (PST) X-Google-Smtp-Source: AK7set+1pykQLK/lxRtt7ZIYFTiUVV6+vHUp9nQyWRO9ZC1d0OjPhpUOcW103upv9wAlGMWHlDI/ X-Received: by 2002:a2e:575d:0:b0:292:7e94:82e5 with SMTP id r29-20020a2e575d000000b002927e9482e5mr4170493ljd.22.1676027352803; Fri, 10 Feb 2023 03:09:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676027352; cv=none; d=google.com; s=arc-20160816; b=xJuH5Sa/cC6BBQp9vriUDJaE0cf281vy4qtJ74GyeiOeccsMJfGEbG35xvJQWQwXgk RuKVXs4Ub0ksp91RKmr2jJS4GjI6VujkbleC/pZ4ULIUr7Fs6KdtO/5HqDkCLwZeycYZ waX3NKHrkMc8hiWzwU7YOyBQ+tgAc7gkZee5Ok5FPDspCODFUA5Cw62OplVq07k03BRr VUjB49Gd+P58z9IX2SkBJxPmpQeRz0oZHcox/tGJ8boximxMrJoiY9eX983qJ02BPAyv Xp3YV6KhYtMH8igHqn9ACbXWITAxrVuqs+xWLdu9v41issRt51eGyu/VzN8uyDqHDDyV VZig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from; bh=app0qQSaT6llQdUKo9/v2+mE0KtIF5Q31OcTwqAapcc=; b=i4ksVcVqgA8+78pDUD9pB+vUOOuCVEWCC4Ql0BfVkP2oiuoENtXJAmOXfGrBGSydY+ hJeF4kKg59K6P9m3Zs12CWoBxYkTBacg8I9l+AJCInLK5yGa7Wjt34zfKOofEFuPQRj8 Arnbhvgfr+YXMuWEX4JRfu4sge8v9w/jig2Dv9oEz8xDlDNjDAOxr419r/OGiWmqDIWM u0uOeAaiDfjzztDq3qbYvn3U+0J22tVeflMf/H+QzDtreRpqeoSIa7fkdLPmKWXwNgIX /c+Pm19tm0FHRR/aBVmt1tGF+9yBv3EICyde8PIHAFrFn5QfvoxC8lh1pmk+mH90ZhtV V2qg== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=pass (google.com: domain of roberto.foglietta@linuxteam.org designates 5.144.164.165 as permitted sender) smtp.mailfrom=roberto.foglietta@linuxteam.org Return-Path: Received: from relay04.th.seeweb.it (relay04.th.seeweb.it. [5.144.164.165]) by gmr-mx.google.com with ESMTPS id z7-20020a2ebcc7000000b00293215eee9esi220068ljp.2.2023.02.10.03.09.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Feb 2023 03:09:12 -0800 (PST) Received-SPF: pass (google.com: domain of roberto.foglietta@linuxteam.org designates 5.144.164.165 as permitted sender) client-ip=5.144.164.165; Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of roberto.foglietta@linuxteam.org designates 5.144.164.165 as permitted sender) smtp.mailfrom=roberto.foglietta@linuxteam.org Received: from localhost.localdomain (unknown [IPv6:2a02:8071:3187:7b80:e47:5fa:2d03:1a15]) by m-r1.th.seeweb.it (Postfix) with ESMTPA id 935A12049A; Fri, 10 Feb 2023 12:09:11 +0100 (CET) From: roberto.foglietta@linuxteam.org To: isar-users@googlegroups.com Cc: roberto.foglietta@gmail.com Subject: [PATCH v4] deb-dl-dir class rework to use faster ln -P or fallback to cp Date: Fri, 10 Feb 2023 12:09:08 +0100 Message-Id: <20230210110908.1507520-1-roberto.foglietta@linuxteam.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TUID: 6yiBp+5v15HG From: "Roberto A. Foglietta" deb-dl-dir, feature: faster when using ln -P otherwise fallback to cp The original class functions deb_dl_dir_import/export were using cp to copy debian package to the target rootfs but this approach is quite slow while using hard link does not work if the destination and source dirs are not lying on the same filesystem. Thus, ln -P should fallback to cp when it does not work (which is different from complaining on stderr). Moreover, these two functions have been reworked to reach a straight forward and more compact form. In particular, export function was using bashism to do some kind of comparison which after all is useless because copying back without overwriting just fulfills that part. More rework using sudo in a different way plus a corner case addressingi, in case the spia file exists for some other reasons. Rebased on the current next and bugfix about checking the destination not the source file. Signed-off-by: Roberto A. Foglietta --- meta/classes/deb-dl-dir.bbclass | 53 +++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/meta/classes/deb-dl-dir.bbclass b/meta/classes/deb-dl-dir.bbclass index 7db25251..2a3c7508 100644 --- a/meta/classes/deb-dl-dir.bbclass +++ b/meta/classes/deb-dl-dir.bbclass @@ -78,39 +78,46 @@ debsrc_download() { deb_dl_dir_import() { export pc="${DEBDIR}/${2}" - export rootfs="${1}" - sudo mkdir -p "${rootfs}"/var/cache/apt/archives/ + export sc="${1}/var/cache/apt/archives/" + sudo mkdir -p "${sc}" [ ! -d "${pc}" ] && return 0 - flock -s "${pc}".lock -c ' + export tf=$(cd "${pc}"; ls -1 *.deb | head -n1) + [ ! -e "${pc}/${tf}" ] && return 0 + flock -Fs "${pc}".lock sudo -Es << 'EOFSUDO' 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/ {} + - ' + rm -f "${sc}/${tf}" + ln -Pf -t "${sc}" "${pc}/${tf}" 2>/dev/null ||: + if [ -r "${sc}/${tf}" ]; then + find "${pc}" -type f -iname "*\.deb" -exec \ + ln -Pf -t "${sc}" {} + + else + find "${pc}" -type f -iname "*\.deb" -exec \ + cp -np owner --reflink=auto -t "${sc}" {} + + fi +EOFSUDO } deb_dl_dir_export() { export pc="${DEBDIR}/${2}" - export rootfs="${1}" + export sc="${1}/var/cache/apt/archives/" mkdir -p "${pc}" - flock "${pc}".lock -c ' + export tf=$(cd "${sc}"; ls -1 *.deb | head -n1) + [ ! -e "${sc}/${tf}" ] && return 0 + flock -F "${pc}".lock sudo -Es << 'EOFSUDO' set -e printenv | grep -q BB_VERBOSE_LOGS && set -x - find "${rootfs}"/var/cache/apt/archives/ \ - -maxdepth 1 -type f -iname '*\.deb' |\ - while read p; do - # skip files from a previous export - [ -f "${pc}/${p##*/}" ] && continue - # can not reuse bitbake function here, this is basically - # "repo_contains_package" - package=$(find "${REPO_ISAR_DIR}"/"${DISTRO}" -name ${p##*/}) - if [ -n "$package" ]; then - cmp --silent "$package" "$p" && continue - fi - sudo ln -Pf "${p}" "${pc}" - done - sudo chown -R $(id -u):$(id -g) "${pc}" - ' + rm -f "${pc}/${tf}" + ln -Pf -t "${pc}" "${sc}/${tf}" 2>/dev/null ||: + if [ -r "${pc}/${tf}" ]; then + find "${sc}" -maxdepth 1 -type f -iname '*\.deb' \ + -exec ln -P -t "${pc}" {} + 2>/dev/null ||: + else + find "${sc}" -maxdepth 1 -type f -iname '*\.deb' \ + -exec cp -n --reflink=auto -t "${pc}" {} + + fi + chown -R $(id -u):$(id -g) "${pc}" +EOFSUDO } -- 2.34.1