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 <nalin@redhat.com>
This commit is contained in:
Nalin Dahyabhai 2019-02-20 11:26:33 -05:00
parent 06025caa49
commit 45b0aa27aa
4 changed files with 7 additions and 5 deletions

View File

@ -291,7 +291,7 @@ func (r *imageStore) Save() error {
return errors.Wrapf(ErrStoreIsReadOnly, "not allowed to modify the image store at %q", r.imagespath()) return errors.Wrapf(ErrStoreIsReadOnly, "not allowed to modify the image store at %q", r.imagespath())
} }
if !r.Locked() { if !r.Locked() {
return errors.New("image store is not locked") return errors.New("image store is not locked for writing")
} }
rpath := r.imagespath() rpath := r.imagespath()
if err := os.MkdirAll(filepath.Dir(rpath), 0700); err != nil { if err := os.MkdirAll(filepath.Dir(rpath), 0700); err != nil {

View File

@ -378,7 +378,7 @@ func (r *layerStore) Save() error {
return errors.Wrapf(ErrStoreIsReadOnly, "not allowed to modify the layer store at %q", r.layerspath()) return errors.Wrapf(ErrStoreIsReadOnly, "not allowed to modify the layer store at %q", r.layerspath())
} }
if !r.Locked() { if !r.Locked() {
return errors.New("layer store is not locked") return errors.New("layer store is not locked for writing")
} }
rpath := r.layerspath() rpath := r.layerspath()
if err := os.MkdirAll(filepath.Dir(rpath), 0700); err != nil { if err := os.MkdirAll(filepath.Dir(rpath), 0700); err != nil {

View File

@ -35,7 +35,7 @@ type Locker interface {
// IsReadWrite() checks if the lock file is read-write // IsReadWrite() checks if the lock file is read-write
IsReadWrite() bool IsReadWrite() bool
// Locked() checks if lock is locked // Locked() checks if lock is locked for writing by a thread in this process
Locked() bool Locked() bool
} }

View File

@ -139,9 +139,11 @@ func (l *lockfile) Unlock() {
l.stateMutex.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 { 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. // Touch updates the lock file with the UID of the user.