Xavier schrieb:
On Thu, Sep 17, 2009 at 6:42 PM, Marc - A. Dahlhaus [ Administration |
Westermann GmbH ] <m...@wol.de> wrote:
This is because you check for size and echo the delta on the same level
of the recursion and the condition checking is wrong. We need to check
for the retval of the recursion and actualy throw the error condition up
one level when we exceed the sizelimit. The checking can only work one
recursion level down from the current level because you push the actual
deltas size one level down.

Recursions are fun are't they? ;-D


Both scripts have the same output.
For example :

38866 < 139532 : Ignoring dhcpcd-4.0.2-1-i686.pkg.tar.gz
38866 < 88713 : Ignoring dhcpcd-4.0.2-2-i686.pkg.tar.gz
38866 < 87880 : Ignoring dhcpcd-4.0.3-1-i686.pkg.tar.gz
38866 < 67312 : Ignoring dhcpcd-4.0.4-1-i686.pkg.tar.gz
38866 < 57650 : Ignoring dhcpcd-5.0.2-1-i686.pkg.tar.gz

vs

dhcpcd-3.2.1-1_to_4.0.2-1-i686.delta 139532
dhcpcd-4.0.2-1_to_4.0.2-2-i686.delta 88713
dhcpcd-4.0.2-2_to_4.0.3-1-i686.delta 87880
dhcpcd-4.0.3-1_to_4.0.4-1-i686.delta 67312
dhcpcd-4.0.4-1_to_5.0.2-1-i686.delta 57650

but I checked several other packages as well.

So I am not sure what you are trying to explain.

Scratch the point about the check one level to high. Didn't realized that you reused the var that you passed down one level in the check.

Actually I was using the retval first, I just changed it at the end,
and kept the same result.
But now I just realize there is something wrong about it, and I
actually don't know how it works at all. I set deltaname and newsize
inside a subshell so normally we cannot access these outside.

I think we look at the same problem but from different angles. What i think is needed to do in a cleanup run is to only care about the deltas that need to be added to the new repo. Your plan was to use unneeded ones as an argument for repo-remove, right? We don't need to. We only need to recreate the new repos "deltas"-file content with the delta lines of deltas we want to keep in the repo.

The recursion algorithm as proposed in my first mail takes care that it only adds the deltas that are directly chained to the package version in the repo with its walk down as long as the "delta-quota" is not reached. It will add the lowest delta version first in the return path up to the newest. The rest of deltas is unneeded.

The functions arguments and the vars created in its body are local. This is ok as we

Take a look at attached version that actually implements the whole cleanup this way. It's fast, short and self contained IMO.

What do you think?

I'll integrate it into repo-add and post a patch tomorrow.


Marc
#!/bin/bash

# $1 : package filename
# $2 : sum of delta size to go from this package to the database one
cleanup() {
  grep "${1}$" ${dir}/deltas | while read delta md5sum dsize spkg tpkg
  do
    if cleanup ${spkg} $(( ${2} + ${dsize} ))
    then
      echo "${delta} ${md5sum} ${dsize} ${spkg} ${tpkg}" \
       >> ${dir}/cdeltas
    fi
  done
  [ ${2} -gt ${quota} ] && return 1
  if [ ${2} -eq 0 ]
  then
    rm -f ${dir}/deltas
    [ -f ${dir}/cdeltas ] mv -f ${dir}/cdeltas ${dir}/deltas
  fi
  return 0
}

# list contents of repo from the root of it
ls -1 | while read dir
do
        if [ ! -f ${dir}/desc -o ! -f ${dir}/deltas ]
        then
                continue
        fi
        filename=$(grep -A1 FILENAME ${dir}/desc | tail -n1)
        filesize=$(grep -A1 CSIZE ${dir}/desc | tail -n1)
        quota=$(( ${filesize} * 7 / 10 ))
        cleanup ${filename} 0
done


Reply via email to