From 9d6d692bf1df0c682ff107a85c5d92377e8b5b1c Mon Sep 17 00:00:00 2001 From: Mariusz Mazur Date: Mon, 20 Sep 2004 23:11:54 +0000 Subject: [PATCH] - lots of changes... cleaned up code, etc. - now need to add moving only 'updated' archs Changed files: bin/functions -> 1.2 bin/move.sh -> 1.7 --- bin/functions | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++ bin/move.sh | 26 ++++--------- 2 files changed, 110 insertions(+), 19 deletions(-) diff --git a/bin/functions b/bin/functions index 191a8c0..cfc3eb6 100644 --- a/bin/functions +++ b/bin/functions @@ -1,4 +1,7 @@ +# Note: all functions expect to get N-V-R strings as file arguments (unless +# it's obvious they shouldn't get them of course) + # Read config if [ ! -f ~/.ftpadmrc ]; then echo "Config not found" @@ -15,4 +18,104 @@ log() { echo `date "+%F %T"` "[$scriptname]" "--" "$@" >>~/pld-ftp-admin/log } +if [ "$DEBUG" == "yes" ]; then + rm() + { + echo "RM: $@" >&2 + } + mv() + { + echo "MV: $@" >&2 + } + cd() + { + command cd $1 + echo "CD: $1" >&2 + } +fi + +# Return a list of packages that differ only by version than the one given +# Args: $1 - the package we're intersted in (in N-V-R format) +# Note1: we assume we're in .metadata dir +# Note2: the list returned is newline, not space, separated +# Note3: sets $glob_basename to basename (without V-R) if anybody need's it +glob_packages() +{ + # Get just the name without the version tag + basename=`echo $1|sed -e 's,-[^-]*-[^-]*$,,'` + # Find packages beginning with that name + allfiles=`echo $basename*` + if [ "$allfiles" == "$basename*" ]; then + # No files found + return + fi + allfiles=`echo "$allfiles"|sed -e 's, ,\n,g' -e 's,.src.rpm.info,,g'` + # Filter out files that just begin with basename, but ain't other + # versions of that package + allfiles=`echo "$allfiles"|grep "$basename-[^-]*-[^-]*$"` + echo "$allfiles" +} + +# Generate a list of older packages +# Args: $1 - ftp tree +# $2 - packages we're interested in +find_older_pkgs() +{ + cd "$FTP_DIR/$1/SRPMS/.metadata/" + list="" + for file in $2; do + # "Glob" for other files + allfiles=`glob_packages $file` + # Get just the name without the version tag (we need it) + basename=`echo $file|sed -e 's,-[^-]*-[^-]*$,,'` + # Get only versions + allfiles=`echo "$allfiles"|sed -e "s,^$basename-,,"` + # Sort (note - this ain't perfect sorting) + allfiles=`echo "$allfiles"|sort -n` + # Readd names + allfiles=`echo "$allfiles"|sed -e "s,^,$basename-,"` + # Grep packages < current package + allfiles=`echo "$allfiles"|grep -B 999 "$file"|grep -v "^$file$"` + # Add to the list + allfiles=`echo $allfiles` + list="$list $allfiles" + done + echo $list +} + +# Generate a list of all packages +# Args: $1 - ftp tree +# $2 - packages we're interested in +find_all_pkgs() +{ + cd "$FTP_DIR/$1/SRPMS/.metadata/" + list="" + for file in $2; do + # "Glob" for other files + allfiles=`glob_packages $file` + # Add to the list + allfiles=`echo $allfiles` + list="$list $allfiles" + done + echo $list +} + +# Remove packages in given tree +# Args: $1 - ftp tree +# $2 - list of packages (info files) to remove +remove_pkgs() { + cd "$FTP_DIR/$1/SRPMS/.metadata/" + for srcfile in $2; do + # Remove all files connected to the old src.rpm + # (+ the src.rpm itself) + for i in `grep '^file:' $srcfile.src.rpm.info`; do + arch=`echo $i|cut -d: -f 2` + file=`echo $i|cut -d: -f 3` + rm "$FTP_DIR/$1/$arch/RPMS/$file" + done + # And finally remove the .info file + rm $srcfile.src.rpm.info + done +} + # vi: syntax=sh diff --git a/bin/move.sh b/bin/move.sh index 1353252..5698f4f 100755 --- a/bin/move.sh +++ b/bin/move.sh @@ -46,25 +46,13 @@ if [ "$waserror" != "0" ]; then exit fi -# Remove old packages -cd "$FTP_DIR/$to/SRPMS/.metadata/" -for srcfile in $files; do - basename=`echo $srcfile|sed -e 's,-[^-]*-[^-]*$,,'` - for oldinfofile in $basename*; do - if [ "$oldinfofile" == "$basename*" ]; then - # No previous files - continue - fi - # Remove all files connected to the old src.rpm (+ the src.rpm itself) - for i in `grep '^file:' $oldinfofile`; do - arch=`echo $i|cut -d: -f 2` - file=`echo $i|cut -d: -f 3` - rm "$FTP_DIR/$to/$arch/RPMS/$file" - done - # And finally remove the .info file - rm $oldinfofile - done -done +# Remove packages older than the ones we're moving in $from tree +olderpkgs=`find_older_pkgs "$from" "$files"` +remove_pkgs "$from" "$olderpkgs" + +# Remove old packages in destination tree +olderpkgs=`find_all_pkgs "$to" "$files"` +remove_pkgs "$to" "$olderpkgs" # Move the new packages cd "$FTP_DIR/$from/SRPMS/.metadata/" -- 2.44.0