]> git.pld-linux.org Git - projects/pld-ftp-admin.git/commitdiff
- lots of changes... cleaned up code, etc.
authorMariusz Mazur <mmazur@pld-linux.org>
Mon, 20 Sep 2004 23:11:54 +0000 (23:11 +0000)
committerMariusz Mazur <mmazur@pld-linux.org>
Mon, 20 Sep 2004 23:11:54 +0000 (23:11 +0000)
- now need to add moving only 'updated' archs

Changed files:
    bin/functions -> 1.2
    bin/move.sh -> 1.7

bin/functions
bin/move.sh

index 191a8c0ca101bed8b930c161a42bec974e3c8943..cfc3eb6470c4688310ef836095f83f255cd69ff8 100644 (file)
@@ -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
index 135325235a49728d63932bca415078bbaf620905..5698f4fa8a377ed0d291a9efcfdc3326f2f5802b 100755 (executable)
@@ -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/"
This page took 0.102786 seconds and 4 git commands to generate.