Correctly handle lockfiles without writes

A newly created lock-file is of size zero, which happens for example
if you reset the storage state. In this state, lockfile.Modified()
always returns true, because it thinks any short read means something
changed.

I ran into this with the image store, which was empty (using images
from a different store), and it keept re-reading the image store all
the time even if nothing changed (i.e. both lock file reads returned
zero bytes).

The proper way to handle this seems to be to compare partial reads
also.

Signed-off-by: Alexander Larsson <alexl@redhat.com>
This commit is contained in:
Alexander Larsson 2022-10-17 11:27:04 +02:00
parent ebf857fda6
commit ddb5de3f4a
1 changed files with 4 additions and 3 deletions

View File

@ -251,9 +251,10 @@ func (l *lockfile) Modified() (bool, error) {
if err != nil {
return true, err
}
if n != len(l.lw) {
return true, nil
}
// It is important to handle the partial read case, because
// the initial size of the lock file is zero, which is a valid
// state (no writes yet)
currentLW = currentLW[:n]
oldLW := l.lw
l.lw = currentLW
return !bytes.Equal(currentLW, oldLW), nil