[pacman-dev] [MAKEPKG][PATCH] makepkg-do-not-count-hard-links-multiple-times
Uses stat -c '%i %s' and sort -u to count hardlink one time. Gives same result than cat | wc -c without harlinks and good result with hardlinks. Doesn't use filenames
Uses stat -c '%i %s' and sort -u to count hardlink one time. Gives same result than cat | wc -c without harlinks and good result with hardlinks. Doesn't use filenames
From cf4ef0333ccc6f080882ee9f3c27049be41bce67 Mon Sep 17 00:00:00 2001 From: nenesse <la.luge@free.fr> Date: Sun, 27 Oct 2019 12:08:36 +0100 Subject: [PATCH] makepkg-do-not-count-hard-links-multiple-times. uses stat -c '%i %s' and sort -u to count hardlink one time. Gives same result than cat | wc -c without harlinks and good result with hardlinks. Doesn't use filenames To: mailto:pacman-dev@archlinux.org
--- configure.ac | 6 ++--- scripts/libmakepkg/util/dirsize.sh.in | 35 +++++++++++++++++++++++++++ scripts/makepkg.sh.in | 2 +- 3 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 scripts/libmakepkg/util/dirsize.sh.in diff --git a/configure.ac b/configure.ac index d68b3591..5d8f8747 100644 --- a/configure.ac +++ b/configure.ac @@ -370,18 +370,18 @@ GCC_VISIBILITY_CC # Host-dependant definitions DEFAULT_SEDINPLACEFLAGS=" --follow-symlinks -i" -INODECMD="stat -c '%i %n'" +INODECMD="stat -c '%i %s'" STRIP_BINARIES="--strip-all" STRIP_SHARED="--strip-unneeded" STRIP_STATIC="--strip-debug" case "${host_os}" in *bsd*) - INODECMD="stat -f '%i %N'" + INODECMD="stat -f '%i %z'" DEFAULT_SEDINPLACEFLAGS=" -i \"\"" ;; darwin*) host_os_darwin=yes - INODECMD="/usr/bin/stat -f '%i %N'" + INODECMD="/usr/bin/stat -f '%i %z'" DEFAULT_SEDINPLACEFLAGS=" -i ''" STRIP_BINARIES="" STRIP_SHARED="-S" diff --git a/scripts/libmakepkg/util/dirsize.sh.in b/scripts/libmakepkg/util/dirsize.sh.in new file mode 100644 index 00000000..a0bd2b3f --- /dev/null +++ b/scripts/libmakepkg/util/dirsize.sh.in @@ -0,0 +1,35 @@ +#!/usr/bin/bash +# +# dirsize.sh - calculate size of all files in a directory +# +# Copyright (c) 2019 Pacman Development Team <pacman-dev@archlinux.org> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# + +[[ -n "$LIBMAKEPKG_UTIL_DIRSIZE_SH" ]] && return +LIBMAKEPKG_UTIL_DIRSIZE_SH=1 + +LIBRARY=${LIBRARY:-'/usr/share/makepkg'} + + +dirsize() { + local size=0 sz _ + + while read _ sz; do + size=$(( size + sz )) + done < <(find . -type f -exec @INODECMD@ '{}' + 2>/dev/null|sort -u) + + echo $size +} diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in index 997c8668..f7a9459b 100644 --- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -584,7 +584,7 @@ write_kv_pair() { } write_pkginfo() { - local size="$(find . -type f -exec cat {} + 2>/dev/null | wc -c)" + local size="$(dirsize)" merge_arch_attrs -- 2.23.0
On 27/10/19 10:26 pm, la.luge@free.fr wrote:
Uses stat -c '%i %s' and sort -u to count hardlink one time. Gives same result than cat | wc -c without harlinks and good result with hardlinks. Doesn't use filenames
From cf4ef0333ccc6f080882ee9f3c27049be41bce67 Mon Sep 17 00:00:00 2001 From: nenesse <la.luge@free.fr> Date: Sun, 27 Oct 2019 12:08:36 +0100 Subject: [PATCH] makepkg-do-not-count-hard-links-multiple-times. uses stat -c '%i %s' and sort -u to count hardlink one time. Gives same result than cat | wc -c without harlinks and good result with hardlinks. Doesn't use filenames To: mailto:pacman-dev@archlinux.org
--- configure.ac | 6 ++--- scripts/libmakepkg/util/dirsize.sh.in | 35 +++++++++++++++++++++++++++ scripts/makepkg.sh.in | 2 +- 3 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 scripts/libmakepkg/util/dirsize.sh.in
diff --git a/configure.ac b/configure.ac index d68b3591..5d8f8747 100644 --- a/configure.ac +++ b/configure.ac @@ -370,18 +370,18 @@ GCC_VISIBILITY_CC
# Host-dependant definitions DEFAULT_SEDINPLACEFLAGS=" --follow-symlinks -i" -INODECMD="stat -c '%i %n'" +INODECMD="stat -c '%i %s'"
So... I'm assuming you did not look at where else INODECMD is used in the code base?
participants (2)
-
Allan McRae
-
la.luge@free.fr