From mboxrd@z Thu Jan 1 00:00:00 1970 X-GM-THRID: 7197029299818332160 X-Received: by 2002:a2e:8802:0:b0:290:6531:39ab with SMTP id x2-20020a2e8802000000b00290653139abmr3483748ljh.73.1675688964332; Mon, 06 Feb 2023 05:09:24 -0800 (PST) X-BeenThere: isar-users@googlegroups.com Received: by 2002:a2e:9048:0:b0:28b:86c7:a456 with SMTP id n8-20020a2e9048000000b0028b86c7a456ls1534660ljg.11.-pod-prod-gmail; Mon, 06 Feb 2023 05:09:22 -0800 (PST) X-Google-Smtp-Source: AK7set/BeewcXY3q9KxwjdgoV+t1CDkrpAK0tN77EcuEaZTb/57kyGXW86bQ1vFZcl0KUx3apHaW X-Received: by 2002:a2e:8297:0:b0:289:ea7b:8978 with SMTP id y23-20020a2e8297000000b00289ea7b8978mr6760346ljg.8.1675688962804; Mon, 06 Feb 2023 05:09:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675688962; cv=none; d=google.com; s=arc-20160816; b=dGn4hd/Ah+b5TacDVsZSoySR8TmLcxFfACTDohryjT1SmiO8mHCFc8vWFk/flPdmUR 8TC+8qndctnYQmyc/rZTHrQ+VLD8ScBqMWRwDtQsFsd3mX6svkYklJhGZ8/La8BXGUWT THBNC/6Le0tN/zzLlLglWN3CA3qEsAV+NQB69PA1jkK2l2G1ZiS0AWfLUEflePUoLjYz vCyap6TxKUttaDqF0XaCRd8QMtVJdtBUjRQ9IJ92VoO+A9X5b+Fn4iEbZvAxj8mSRKaa Yh7ruqlpkqiO8rkWFhxYB3tx1YvXo6KRj73OlgDR+frl2G2BeMcQAJ5RO5srZreeyH60 HMIw== 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=WVeESxTUTC2XOhssbDUkZisL//GqS6vL5q9r5TrmnSg=; b=bO09+ww76R/1hbArHYk+ljaNkdogmYJKaa6lLdpf2O1D7LPgM4XZicgf7fImsPmUA4 4+879VENzfIf1ZtJdyGaZW6RmgKdrFGLCkNxwGFSjmYe5f0eXzKLYDx2gFiWYr46uhpT 4GfhoqTdXmnMGtE+nGiAU9YpAi6IuQX0I+PJYVaGRI5ynDqdq9JG2C56lwkZmCq/G6y0 NwEG90Wl4I4GkeIvbTOlN4NsHkP5fC1mmGJnWPpQcQNuTwk80rZdd8UjVZfbS7DsG2Mr IXs3Ws9kIyqiRs0nhdo4Hey8bdPWrQF8aQp4tm8qDo0/5ZdeTP6hv+hb4P5HzS9/jR7O bBwQ== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=pass (google.com: domain of roberto.foglietta@linuxteam.org designates 5.144.164.169 as permitted sender) smtp.mailfrom=roberto.foglietta@linuxteam.org Return-Path: Received: from relay08.th.seeweb.it (relay08.th.seeweb.it. [5.144.164.169]) by gmr-mx.google.com with ESMTPS id d21-20020a05651c089500b0029059a3a89asi421054ljq.4.2023.02.06.05.09.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Feb 2023 05:09:22 -0800 (PST) Received-SPF: pass (google.com: domain of roberto.foglietta@linuxteam.org designates 5.144.164.169 as permitted sender) client-ip=5.144.164.169; Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of roberto.foglietta@linuxteam.org designates 5.144.164.169 as permitted sender) smtp.mailfrom=roberto.foglietta@linuxteam.org Received: from localhost.localdomain (unknown [IPv6:2a02:8071:3187:7b80:4081:d461:5a4:5549]) by m-r2.th.seeweb.it (Postfix) with ESMTPA id 9FC103FD02; Mon, 6 Feb 2023 14:09:21 +0100 (CET) From: roberto.foglietta@linuxteam.org To: isar-users@googlegroups.com Cc: roberto.foglietta@gmail.com Subject: [PATCH] deb-dl-dir class rework to use faster ln -P or fallback to cp Date: Mon, 6 Feb 2023 14:09:19 +0100 Message-Id: <20230206130919.327653-1-roberto.foglietta@linuxteam.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TUID: 7JrSO1YwnE2q 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. Signed-off-by: Roberto A. Foglietta --- meta/classes/deb-dl-dir.bbclass | 41 ++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/meta/classes/deb-dl-dir.bbclass b/meta/classes/deb-dl-dir.bbclass index 3b1517dc..22de7bf6 100644 --- a/meta/classes/deb-dl-dir.bbclass +++ b/meta/classes/deb-dl-dir.bbclass @@ -78,39 +78,44 @@ 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 + export tf=$(ls -1 "${pc}"/*.deb | head -n1) + [ ! -e "${tf}" ] && 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 \ - cp -n --no-preserve=owner -t "${rootfs}"/var/cache/apt/archives/ {} + + sudo ln -Pf -t "${sc}" "${tf}" 2>/dev/null ||: + if [ -r "${tf}" ]; then + sudo find "${pc}" -type f -iname "*\.deb" -exec \ + ln -Pf -t "${sc}" {} + + else + sudo find "${pc}" -type f -iname "*\.deb" -exec \ + cp -np owner --reflink=auto -t "${sc}" {} + + fi ' } deb_dl_dir_export() { export pc="${DEBDIR}/${2}" - export rootfs="${1}" + export sc="${1}/var/cache/apt/archives/" mkdir -p "${pc}" + export tf=$(ls -1 "${sc}"/*.deb | head -n1) + [ ! -e "${tf}" ] && return 0 flock "${pc}".lock -c ' 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 cp -n "${p}" "${pc}" - done + sudo ln -Pf -t "${pc}" "${tf}" 2>/dev/null ||: + if [ -r "${tf}" ]; then + sudo find "${sc}" -maxdepth 1 -type f -iname '*\.deb' \ + -exec ln -P -t "${pc}" {} + 2>/dev/null ||: + else + sudo find "${sc}" -maxdepth 1 -type f -iname '*\.deb' \ + -exec cp -n --reflink=auto -t "${pc}" {} + + fi sudo chown -R $(id -u):$(id -g) "${pc}" ' } -- 2.34.1