From 45b0aa27aa4e17f304ce164a028a86acc00e886a Mon Sep 17 00:00:00 2001 From: Nalin Dahyabhai Date: Wed, 20 Feb 2019 11:26:33 -0500 Subject: [PATCH] Locker.Locked(): clarify that we're checking for write locks Clarify that Locker.Locked() checks if we have a write lock, since that's what we care about whenever we check it. Signed-off-by: Nalin Dahyabhai --- images.go | 2 +- layers.go | 2 +- lockfile.go | 2 +- lockfile_unix.go | 6 ++++-- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/images.go b/images.go index 93505f5fb..6001c207b 100644 --- a/images.go +++ b/images.go @@ -291,7 +291,7 @@ func (r *imageStore) Save() error { return errors.Wrapf(ErrStoreIsReadOnly, "not allowed to modify the image store at %q", r.imagespath()) } if !r.Locked() { - return errors.New("image store is not locked") + return errors.New("image store is not locked for writing") } rpath := r.imagespath() if err := os.MkdirAll(filepath.Dir(rpath), 0700); err != nil { diff --git a/layers.go b/layers.go index d612f0459..4fc20d036 100644 --- a/layers.go +++ b/layers.go @@ -378,7 +378,7 @@ func (r *layerStore) Save() error { return errors.Wrapf(ErrStoreIsReadOnly, "not allowed to modify the layer store at %q", r.layerspath()) } if !r.Locked() { - return errors.New("layer store is not locked") + return errors.New("layer store is not locked for writing") } rpath := r.layerspath() if err := os.MkdirAll(filepath.Dir(rpath), 0700); err != nil { diff --git a/lockfile.go b/lockfile.go index e3b82fce4..3a1befcbe 100644 --- a/lockfile.go +++ b/lockfile.go @@ -35,7 +35,7 @@ type Locker interface { // IsReadWrite() checks if the lock file is read-write IsReadWrite() bool - // Locked() checks if lock is locked + // Locked() checks if lock is locked for writing by a thread in this process Locked() bool } diff --git a/lockfile_unix.go b/lockfile_unix.go index 211227012..7dcde875a 100644 --- a/lockfile_unix.go +++ b/lockfile_unix.go @@ -139,9 +139,11 @@ func (l *lockfile) Unlock() { l.stateMutex.Unlock() } -// Locked checks if lockfile is locked. +// Locked checks if lockfile is locked for writing by a thread in this process. func (l *lockfile) Locked() bool { - return l.locked + l.stateMutex.Lock() + defer l.stateMutex.Unlock() + return l.locked && (l.locktype == unix.F_WRLCK) } // Touch updates the lock file with the UID of the user.