From ddb5de3f4a11fb71f660f25b5e7ee22d1df7a380 Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Mon, 17 Oct 2022 11:27:04 +0200 Subject: [PATCH] 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 --- pkg/lockfile/lockfile_unix.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pkg/lockfile/lockfile_unix.go b/pkg/lockfile/lockfile_unix.go index 0e8dcba80..10bcb143a 100644 --- a/pkg/lockfile/lockfile_unix.go +++ b/pkg/lockfile/lockfile_unix.go @@ -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