Added some output to the lock/unlock functions to see if it helps
illustrate the issue better

I also fiddled with the cleanup function in db-update a bit, so it
only calls repo_unlock on an error. Didnt commit the changes, but lets
see if that helps

  
I think I fixed it. The thing is that through
    trap cleanup 0
the function cleanup() is called automatically at the end of the script.
And since cleanup in turn calls
    repo_unlock $reponame $current_arch
the latter fails because $current_arch is "x86_64" and we have already
unlocked each repo before the end of the for loop, resulting in a spurious
error message.
Replacing repo_unlock by
    rm -f $TMPDIR/.repolock.$reponame.*
in cleanup() solves this. (It might be actually better to have a function
delete_repolocks() in db-function that does this...)

I have also moved a few lines down within the
    if [ -n "$ANYPKGS" ]; then  <...> fi
construct. Otherwise one would get the message
    ==> Processing 0 new/updated arch-independent packages for '$reponame'...
even when no package with arch=any is present in staging

See attached patch...

Gute Nacht,
F