They are a shared state across all users of the *LockFile in the process,
and therefore incorrect to use for any single consumer for change tracking.
Direct users to user the new GetLastWrite, ModifiedSince, and RecordWrite,
instead, and convert all c/storage users.
In addition to just being correct, the new API is also more efficient:
- We now initialize stores with GetLastWrite before loading state;
so, we don't trigger an immediate reload on the _second_ use of a store,
due to the problematic semantics of .Modified().
- Unlike Modified() and Touch(), the new APi can be safely used without
locking *LockFile.stateMutex, for a tiny speedup.
The conversion is, for now, trivial, just immediately updating the lastWrite
value after the ModifiedSince call. That will get better.
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
Add lockfile.GetLockFile and lockfile.GetROLockFile (with upper-case
F, as opposed to existing methods with lower-case f) which return a
*LockFile struct, instead of the Locker interface.
This follows the general Go design heuristic: "return structs, accept
interfaces"; more importantly, it allows us to add more methods to the lock
object without breaking the Go API by extending a pre-existing interface.
Should not change behavior.
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
This will replace Lockfile.Locked for the sanity-checking
purposes.
It is, just like Locked never was, NOT a way for a caller
to check the current state. Hence the panic() instead of an
error return.
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
We now use the golang error wrapping format specifier `%w` instead of the
deprecated github.com/pkg/errors package.
Signed-off-by: Sascha Grunert <sgrunert@redhat.com>