diff options
| author | Robert Yang <liezhi.yang@windriver.com> | 2012-02-22 20:38:30 +0800 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2012-02-23 23:59:40 +0000 |
| commit | 6224e30834cbf02d81d72429d121ee5c2eaf0767 (patch) | |
| tree | 997c2c621b29610629f5f41375da463dd9e65337 /scripts | |
| parent | ef29851fe843847ec27598b4cb199a48923b9391 (diff) | |
| download | poky-6224e30834cbf02d81d72429d121ee5c2eaf0767.tar.gz | |
A script to clean obsolete sstate cache files
There would be many obsolete cache files in the SSTATE_DIR after several
builds, this script can remove the obsolete one for a pkg, only leave
the up to date one.
Here is the help text:
sstate-cache-management.sh <OPTION>
Options:
--help, -h
Display this help and exit.
--cache-dir=<sstate cache dir>
Specify sstate cache directory, will use the environment
variable SSTATE_CACHE_DIR if it is not specified.
--remove-duplicated
Remove the duplicated sstate cache files of one package, only
the newest one would be kept.
[YOCTO #1682]
(From OE-Core rev: 7c99ef6d2173b14e1109a540ee5ae47b56d707e7)
Signed-off-by: Robert Yang <liezhi.yang@windriver.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts')
| -rwxr-xr-x | scripts/sstate-cache-management.sh | 135 |
1 files changed, 135 insertions, 0 deletions
diff --git a/scripts/sstate-cache-management.sh b/scripts/sstate-cache-management.sh new file mode 100755 index 0000000000..d0e3abc820 --- /dev/null +++ b/scripts/sstate-cache-management.sh | |||
| @@ -0,0 +1,135 @@ | |||
| 1 | #!/bin/bash | ||
| 2 | |||
| 3 | # Copyright (c) 2012 Wind River Systems, Inc. | ||
| 4 | # | ||
| 5 | # This program is free software; you can redistribute it and/or modify | ||
| 6 | # it under the terms of the GNU General Public License version 2 as | ||
| 7 | # published by the Free Software Foundation. | ||
| 8 | # | ||
| 9 | # This program is distributed in the hope that it will be useful, | ||
| 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
| 12 | # See the GNU General Public License for more details. | ||
| 13 | # | ||
| 14 | # You should have received a copy of the GNU General Public License | ||
| 15 | # along with this program; if not, write to the Free Software | ||
| 16 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
| 17 | # | ||
| 18 | |||
| 19 | usage () { | ||
| 20 | cat << EOF | ||
| 21 | Welcome to sstate cache management utilities. | ||
| 22 | sstate-cache-management.sh <OPTION> | ||
| 23 | |||
| 24 | Options: | ||
| 25 | --help, -h | ||
| 26 | Display this help and exit. | ||
| 27 | |||
| 28 | --cache-dir=<sstate cache dir> | ||
| 29 | Specify sstate cache directory, will use the environment | ||
| 30 | variable SSTATE_CACHE_DIR if it is not specified. | ||
| 31 | |||
| 32 | --remove-duplicated | ||
| 33 | Remove the duplicated sstate cache files of one package, only | ||
| 34 | the newest one would be kept. | ||
| 35 | |||
| 36 | EOF | ||
| 37 | } | ||
| 38 | |||
| 39 | if [ $# -lt 1 ]; then | ||
| 40 | usage | ||
| 41 | exit 0 | ||
| 42 | fi | ||
| 43 | |||
| 44 | # Print error information and exit. | ||
| 45 | echo_error () { | ||
| 46 | echo "ERROR: $1" >&2 | ||
| 47 | exit 1 | ||
| 48 | } | ||
| 49 | |||
| 50 | # Remove the duplicated cache files for the pkg, keep the newest one | ||
| 51 | remove_duplicated () { | ||
| 52 | local all_suffixes="$1" | ||
| 53 | local ava_archs="$2" | ||
| 54 | local total_deleted=0 | ||
| 55 | for suffix in $all_suffixes; do | ||
| 56 | local deleted=0 | ||
| 57 | echo -n "Removing the sstate-xxx_$suffix.tgz ... " | ||
| 58 | # sed twice to avoid the greedy match | ||
| 59 | file_names=`for arch in $ava_archs; do | ||
| 60 | ls sstate-*-$arch-*_$suffix.tgz 2>/dev/null | \ | ||
| 61 | sed -e 's/\(.*\)-'"$arch"'-.*/\1/' \ | ||
| 62 | -e 's/\(.*\)-'"$arch"'-.*/\1/' | ||
| 63 | done | sort -u` | ||
| 64 | |||
| 65 | for fn in $file_names; do | ||
| 66 | for arch in $ava_archs; do | ||
| 67 | ls $fn-$arch-*_$suffix.tgz 2>/dev/null >>/tmp/$fn | ||
| 68 | done | ||
| 69 | # Also delete the .siginfo file | ||
| 70 | to_del=$(ls -t $(cat /tmp/$fn) | sed -n '1!p' | sed -e 'p' -e 's/$/.siginfo/') | ||
| 71 | rm -f $to_del | ||
| 72 | let deleted=$deleted+`echo $to_del | wc -w` | ||
| 73 | rm -f /tmp/$fn | ||
| 74 | done | ||
| 75 | echo "($deleted files)" | ||
| 76 | let total_deleted=$total_deleted+$deleted | ||
| 77 | done | ||
| 78 | echo "$total_deleted files have been removed" | ||
| 79 | } | ||
| 80 | |||
| 81 | # Parse arguments | ||
| 82 | while [ -n "$1" ]; do | ||
| 83 | case $1 in | ||
| 84 | --cache-dir=*) | ||
| 85 | cache_dir=`echo $1 | sed -e 's#^--cache-dir=##' -e 's#/*$##' | xargs readlink -f` | ||
| 86 | [ -d "$cache_dir" ] || echo_error "Invalid argument to --cache-dir" | ||
| 87 | shift | ||
| 88 | ;; | ||
| 89 | --remove-duplicated) | ||
| 90 | rm_duplicated="yes" | ||
| 91 | shift | ||
| 92 | ;; | ||
| 93 | --help|-h) | ||
| 94 | usage | ||
| 95 | exit 0 | ||
| 96 | ;; | ||
| 97 | *) | ||
| 98 | echo "Invalid arguments $*" | ||
| 99 | echo_error "Try 'sstate-cache-management.sh -h' for more information." | ||
| 100 | ;; | ||
| 101 | esac | ||
| 102 | done | ||
| 103 | |||
| 104 | # sstate cache directory, use environment variable SSTATE_CACHE_DIR | ||
| 105 | # if it was not specified, otherwise, error. | ||
| 106 | [ -n "$cache_dir" ] || cache_dir=$SSTATE_CACHE_DIR | ||
| 107 | [ -d "$cache_dir" ] || echo_error "Invalid cache directory \"$cache_dir\"" | ||
| 108 | |||
| 109 | cache_dir=`readlink -f $cache_dir` | ||
| 110 | |||
| 111 | topdir=$(dirname $(dirname $(readlink -f $0))) | ||
| 112 | tunedir=$topdir/meta/conf/machine/include | ||
| 113 | [ -d $tunedir ] || echo_error "Can't find the tune directory" | ||
| 114 | |||
| 115 | # Use the "_" to substitute "-", e.g., x86-64 to x86_64 | ||
| 116 | all_archs=`grep -r DEFAULTTUNE $tunedir | \ | ||
| 117 | sed -e 's/.*\"\(.*\)\"/\1/' -e 's/-/_/g' | sort -u` | ||
| 118 | # Add the qemu archs | ||
| 119 | all_archs="$all_archs qemuarm qemux86 qemumips qemuppc" | ||
| 120 | |||
| 121 | all_suffixes="deploy-rpm deploy-ipk deploy-deb deploy package populate-lic populate-sysroot" | ||
| 122 | |||
| 123 | cd $cache_dir | ||
| 124 | |||
| 125 | echo "Figuring out the archs in the sstate cache dir ..." | ||
| 126 | for arch in $all_archs; do | ||
| 127 | ls | grep -q -w $arch | ||
| 128 | [ $? -eq 0 ] && ava_archs="$ava_archs $arch" | ||
| 129 | done | ||
| 130 | echo "The following archs have been found in the sstate cache dir:" | ||
| 131 | echo $ava_archs | ||
| 132 | |||
| 133 | if [ "$rm_duplicated" == "yes" -a -n "$ava_archs" ]; then | ||
| 134 | remove_duplicated "$all_suffixes" "$ava_archs" | ||
| 135 | fi | ||
