From mboxrd@z Thu Jan 1 00:00:00 1970 X-GM-THRID: 7197029299818332160 X-Received: by 2002:a2e:1651:0:b0:28e:50ad:8108 with SMTP id 17-20020a2e1651000000b0028e50ad8108mr364192ljw.192.1675756347518; Mon, 06 Feb 2023 23:52:27 -0800 (PST) X-BeenThere: isar-users@googlegroups.com Received: by 2002:a2e:d01:0:b0:290:51e7:45ed with SMTP id 1-20020a2e0d01000000b0029051e745edls1966046ljn.8.-pod-prod-gmail; Mon, 06 Feb 2023 23:52:26 -0800 (PST) X-Google-Smtp-Source: AK7set/Dj5qAC/Uvd5wxaW5CTi/4rIDxxKUeX1B6O1Ae3fMyY7ou9/vpusHFyW2SKpDHMwsqIXPh X-Received: by 2002:a2e:8396:0:b0:293:fca:ffb7 with SMTP id x22-20020a2e8396000000b002930fcaffb7mr665547ljg.10.1675756346015; Mon, 06 Feb 2023 23:52:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675756346; cv=none; d=google.com; s=arc-20160816; b=myoOpkzSjuD8FkmqASw9vNYRXsCID3s65wfBdpyiK0f3z/vBJIfxcSbBqVY249JT6t uV3TBNj0fDO9TcsxFizjqF58zzT2pG7ysZ+EFPYRjINuNPPth1VXTM26FgpvhByx6SWO igJsW4LmZK0Ib/fG61TIEjmAde2Yrluvhg7jCfceOnG4wrPoen0qh8pwK1wGc8Sc2/pq pP42BJWL7IG6YmfZlDIpfanqtMrAwwjALsbhhTvdw4RvHHemaXp4A0jZiFasLWAzM0FK dVVcqe7e4bR6HP6fF6rc+04GECvNfSFlyqOR3n9su8oRa/pahLnUjLiGnxd+7zrPgXnx r0oQ== 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=Tu9n7DL6Lec5AHMmYdJsEZgyHgxHlhV1m0er18AaLdg=; b=CvW+OCF44AlmO2yfm7MS35Ip+OCWQ27ryQuG6emp6rllfOuvws9pMt+DH3b16h6dAG 0cvLA4/aJLAaOQMjHQb/0Wnd/VqOcUrwbLKHT0ZdTp1z7rAng/8AENKrmifhfZYxFYKF HkVessyHmqTcK2XW6Vjyqrr2ljqVLSG5yHWR8rSKefCCBTaLbI4Qa09PmJVNVikLosV/ qzdatLVI1AmHwFLfYVC2bYClbk5VfUrA4AZPkE1pJ9melirEMK3SANBOhWK0ClaJJ4RI 4TGAnJeWipbGyuObNiJbk5jvUkV1Itkbqq0La+7yj52ASv+HAMBUq9wd+VvSNRBl7w+V qrzg== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=pass (google.com: domain of roberto.foglietta@linuxteam.org designates 2001:4b7a:2000:18::171 as permitted sender) smtp.mailfrom=roberto.foglietta@linuxteam.org Return-Path: Received: from m-r2.th.seeweb.it (m-r2.th.seeweb.it. [2001:4b7a:2000:18::171]) by gmr-mx.google.com with ESMTPS id p22-20020a2ea416000000b002905672e241si428349ljn.5.2023.02.06.23.52.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Feb 2023 23:52:26 -0800 (PST) Received-SPF: pass (google.com: domain of roberto.foglietta@linuxteam.org designates 2001:4b7a:2000:18::171 as permitted sender) client-ip=2001:4b7a:2000:18::171; Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of roberto.foglietta@linuxteam.org designates 2001:4b7a:2000:18::171 as permitted sender) smtp.mailfrom=roberto.foglietta@linuxteam.org Received: from localhost.localdomain (unknown [IPv6:2a02:8071:3187:7b80:582:9dd8:9cc7:d7ab]) by m-r2.th.seeweb.it (Postfix) with ESMTPA id 05E363F409; Tue, 7 Feb 2023 08:52:25 +0100 (CET) From: roberto.foglietta@linuxteam.org To: isar-users@googlegroups.com Cc: roberto.foglietta@gmail.com Subject: [PATCH v3] deb-dl-dir class rework to use faster ln -P or fallback to cp Date: Tue, 7 Feb 2023 08:52:22 +0100 Message-Id: <20230207075222.390954-1-roberto.foglietta@linuxteam.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TUID: kGYnlQqar7rD 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 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..1fe9d40c 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=$(ls -1 "${pc}"/*.deb | head -n1) + [ ! -e "${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}/"$(basename "${tf}") + ln -Pf -t "${sc}" "${tf}" 2>/dev/null ||: + if [ -r "${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=$(ls -1 "${sc}"/*.deb | head -n1) + [ ! -e "${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}/"$(basename "${tf}") + ln -Pf -t "${pc}" "${tf}" 2>/dev/null ||: + if [ -r "${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