This form is available since Go 1.22 (see
https://tip.golang.org/ref/spec#For_range) and will probably be seen
more and more in the new code.
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
lockfile.LastWrite allows callers to explicitly
track state across *LockFile.{GetLastWrite,ModifiedSince,
RecordWrite}.
*LockFile.{Modified,Touch} are now implemented
in terms of these APIs.
NOTE: This changes behavior, Touch() now updates
the built-in state only on success. Either way there
can be suprious modification reports.
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>
.Locked() will be going away. These are just smoke-tests,
so use the .Assert* methods (which are not usable with other
concurrent users).
The AssertLockedForWriting() tests probably don't work on
Windows, but that was the case previously as well.
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
Check for errors from command Wait() methods. Not sure how this
inconsistency even landed in the first version of this test.
Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
go { cmd.Run() } means the cmd will be destructed,
and stdin/stdout/stderr closed, concurrently with
other goroutines trying to access stdin/stdout/stderr.
Instead, do it the more traditional way and let the callers
who create those subprocesses explicitly manage their lifetime.
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
The Go race detector will kill the test if it tries to have more than
8192 goroutines active at once, so start 8,000 instead of 100,000.
Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
Fix a race where the state lock in a Unixy lockfile structure wasn't
being used to protect access to all of the structure's state fields.
Fix usage of sync/atomic in the corresponding unit tests to not mix
atomic adds and reads with non-atomic reads, something which the race
detector complained about.
Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>