+# 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"
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
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/"