vendor: _actually_ update containers/storage?
I obviously bungled my attempt in #1391 so this is fixing that. Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
This commit is contained in:
parent
0b736bb43f
commit
4a65baf87b
7 changed files with 201 additions and 131 deletions
116
vendor/github.com/containers/storage/lockfile.go
generated
vendored
116
vendor/github.com/containers/storage/lockfile.go
generated
vendored
|
@ -2,14 +2,11 @@ package storage
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/containers/storage/pkg/stringid"
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"golang.org/x/sys/unix"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// A Locker represents a file lock where the file is used to cache an
|
// A Locker represents a file lock where the file is used to cache an
|
||||||
|
@ -33,16 +30,8 @@ type Locker interface {
|
||||||
IsReadWrite() bool
|
IsReadWrite() bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type lockfile struct {
|
|
||||||
mu sync.Mutex
|
|
||||||
file string
|
|
||||||
fd uintptr
|
|
||||||
lw string
|
|
||||||
locktype int16
|
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
lockfiles map[string]*lockfile
|
lockfiles map[string]Locker
|
||||||
lockfilesLock sync.Mutex
|
lockfilesLock sync.Mutex
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -52,7 +41,7 @@ func GetLockfile(path string) (Locker, error) {
|
||||||
lockfilesLock.Lock()
|
lockfilesLock.Lock()
|
||||||
defer lockfilesLock.Unlock()
|
defer lockfilesLock.Unlock()
|
||||||
if lockfiles == nil {
|
if lockfiles == nil {
|
||||||
lockfiles = make(map[string]*lockfile)
|
lockfiles = make(map[string]Locker)
|
||||||
}
|
}
|
||||||
cleanPath := filepath.Clean(path)
|
cleanPath := filepath.Clean(path)
|
||||||
if locker, ok := lockfiles[cleanPath]; ok {
|
if locker, ok := lockfiles[cleanPath]; ok {
|
||||||
|
@ -61,12 +50,10 @@ func GetLockfile(path string) (Locker, error) {
|
||||||
}
|
}
|
||||||
return locker, nil
|
return locker, nil
|
||||||
}
|
}
|
||||||
fd, err := unix.Open(cleanPath, os.O_RDWR|os.O_CREATE, unix.S_IRUSR|unix.S_IWUSR)
|
locker, err := getLockFile(path, false) // platform dependent locker
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(err, "error opening %q", cleanPath)
|
return nil, err
|
||||||
}
|
}
|
||||||
unix.CloseOnExec(fd)
|
|
||||||
locker := &lockfile{file: path, fd: uintptr(fd), lw: stringid.GenerateRandomID(), locktype: unix.F_WRLCK}
|
|
||||||
lockfiles[filepath.Clean(path)] = locker
|
lockfiles[filepath.Clean(path)] = locker
|
||||||
return locker, nil
|
return locker, nil
|
||||||
}
|
}
|
||||||
|
@ -77,7 +64,7 @@ func GetROLockfile(path string) (Locker, error) {
|
||||||
lockfilesLock.Lock()
|
lockfilesLock.Lock()
|
||||||
defer lockfilesLock.Unlock()
|
defer lockfilesLock.Unlock()
|
||||||
if lockfiles == nil {
|
if lockfiles == nil {
|
||||||
lockfiles = make(map[string]*lockfile)
|
lockfiles = make(map[string]Locker)
|
||||||
}
|
}
|
||||||
cleanPath := filepath.Clean(path)
|
cleanPath := filepath.Clean(path)
|
||||||
if locker, ok := lockfiles[cleanPath]; ok {
|
if locker, ok := lockfiles[cleanPath]; ok {
|
||||||
|
@ -86,99 +73,10 @@ func GetROLockfile(path string) (Locker, error) {
|
||||||
}
|
}
|
||||||
return locker, nil
|
return locker, nil
|
||||||
}
|
}
|
||||||
fd, err := unix.Open(cleanPath, os.O_RDONLY, 0)
|
locker, err := getLockFile(path, true) // platform dependent locker
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(err, "error opening %q", cleanPath)
|
return nil, err
|
||||||
}
|
}
|
||||||
unix.CloseOnExec(fd)
|
|
||||||
locker := &lockfile{file: path, fd: uintptr(fd), lw: stringid.GenerateRandomID(), locktype: unix.F_RDLCK}
|
|
||||||
lockfiles[filepath.Clean(path)] = locker
|
lockfiles[filepath.Clean(path)] = locker
|
||||||
return locker, nil
|
return locker, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lock locks the lock file
|
|
||||||
func (l *lockfile) Lock() {
|
|
||||||
lk := unix.Flock_t{
|
|
||||||
Type: l.locktype,
|
|
||||||
Whence: int16(os.SEEK_SET),
|
|
||||||
Start: 0,
|
|
||||||
Len: 0,
|
|
||||||
Pid: int32(os.Getpid()),
|
|
||||||
}
|
|
||||||
l.mu.Lock()
|
|
||||||
for unix.FcntlFlock(l.fd, unix.F_SETLKW, &lk) != nil {
|
|
||||||
time.Sleep(10 * time.Millisecond)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Unlock unlocks the lock file
|
|
||||||
func (l *lockfile) Unlock() {
|
|
||||||
lk := unix.Flock_t{
|
|
||||||
Type: unix.F_UNLCK,
|
|
||||||
Whence: int16(os.SEEK_SET),
|
|
||||||
Start: 0,
|
|
||||||
Len: 0,
|
|
||||||
Pid: int32(os.Getpid()),
|
|
||||||
}
|
|
||||||
for unix.FcntlFlock(l.fd, unix.F_SETLKW, &lk) != nil {
|
|
||||||
time.Sleep(10 * time.Millisecond)
|
|
||||||
}
|
|
||||||
l.mu.Unlock()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Touch updates the lock file with the UID of the user
|
|
||||||
func (l *lockfile) Touch() error {
|
|
||||||
l.lw = stringid.GenerateRandomID()
|
|
||||||
id := []byte(l.lw)
|
|
||||||
_, err := unix.Seek(int(l.fd), 0, os.SEEK_SET)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
n, err := unix.Write(int(l.fd), id)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if n != len(id) {
|
|
||||||
return unix.ENOSPC
|
|
||||||
}
|
|
||||||
err = unix.Fsync(int(l.fd))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Modified indicates if the lock file has been updated since the last time it was loaded
|
|
||||||
func (l *lockfile) Modified() (bool, error) {
|
|
||||||
id := []byte(l.lw)
|
|
||||||
_, err := unix.Seek(int(l.fd), 0, os.SEEK_SET)
|
|
||||||
if err != nil {
|
|
||||||
return true, err
|
|
||||||
}
|
|
||||||
n, err := unix.Read(int(l.fd), id)
|
|
||||||
if err != nil {
|
|
||||||
return true, err
|
|
||||||
}
|
|
||||||
if n != len(id) {
|
|
||||||
return true, unix.ENOSPC
|
|
||||||
}
|
|
||||||
lw := l.lw
|
|
||||||
l.lw = string(id)
|
|
||||||
return l.lw != lw, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// TouchedSince indicates if the lock file has been touched since the specified time
|
|
||||||
func (l *lockfile) TouchedSince(when time.Time) bool {
|
|
||||||
st := unix.Stat_t{}
|
|
||||||
err := unix.Fstat(int(l.fd), &st)
|
|
||||||
if err != nil {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
touched := time.Unix(statTMtimeUnix(st))
|
|
||||||
return when.Before(touched)
|
|
||||||
}
|
|
||||||
|
|
||||||
// IsRWLock indicates if the lock file is a read-write lock
|
|
||||||
func (l *lockfile) IsReadWrite() bool {
|
|
||||||
return (l.locktype == unix.F_WRLCK)
|
|
||||||
}
|
|
||||||
|
|
19
vendor/github.com/containers/storage/lockfile_darwin.go
generated
vendored
Normal file
19
vendor/github.com/containers/storage/lockfile_darwin.go
generated
vendored
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
// +build darwin freebsd
|
||||||
|
|
||||||
|
package storage
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"golang.org/x/sys/unix"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (l *lockfile) TouchedSince(when time.Time) bool {
|
||||||
|
st := unix.Stat_t{}
|
||||||
|
err := unix.Fstat(int(l.fd), &st)
|
||||||
|
if err != nil {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
touched := time.Unix(st.Mtimespec.Unix())
|
||||||
|
return when.Before(touched)
|
||||||
|
}
|
20
vendor/github.com/containers/storage/lockfile_linux.go
generated
vendored
Normal file
20
vendor/github.com/containers/storage/lockfile_linux.go
generated
vendored
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
// +build linux solaris
|
||||||
|
|
||||||
|
package storage
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"golang.org/x/sys/unix"
|
||||||
|
)
|
||||||
|
|
||||||
|
// TouchedSince indicates if the lock file has been touched since the specified time
|
||||||
|
func (l *lockfile) TouchedSince(when time.Time) bool {
|
||||||
|
st := unix.Stat_t{}
|
||||||
|
err := unix.Fstat(int(l.fd), &st)
|
||||||
|
if err != nil {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
touched := time.Unix(st.Mtim.Unix())
|
||||||
|
return when.Before(touched)
|
||||||
|
}
|
115
vendor/github.com/containers/storage/lockfile_unix.go
generated
vendored
Normal file
115
vendor/github.com/containers/storage/lockfile_unix.go
generated
vendored
Normal file
|
@ -0,0 +1,115 @@
|
||||||
|
// +build linux solaris darwin freebsd
|
||||||
|
|
||||||
|
package storage
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/containers/storage/pkg/stringid"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"golang.org/x/sys/unix"
|
||||||
|
)
|
||||||
|
|
||||||
|
func getLockFile(path string, ro bool) (Locker, error) {
|
||||||
|
var fd int
|
||||||
|
var err error
|
||||||
|
if ro {
|
||||||
|
fd, err = unix.Open(path, os.O_RDONLY, 0)
|
||||||
|
} else {
|
||||||
|
fd, err = unix.Open(path, os.O_RDWR|os.O_CREATE, unix.S_IRUSR|unix.S_IWUSR)
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrapf(err, "error opening %q", path)
|
||||||
|
}
|
||||||
|
unix.CloseOnExec(fd)
|
||||||
|
if ro {
|
||||||
|
return &lockfile{file: path, fd: uintptr(fd), lw: stringid.GenerateRandomID(), locktype: unix.F_RDLCK}, nil
|
||||||
|
}
|
||||||
|
return &lockfile{file: path, fd: uintptr(fd), lw: stringid.GenerateRandomID(), locktype: unix.F_WRLCK}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type lockfile struct {
|
||||||
|
mu sync.Mutex
|
||||||
|
file string
|
||||||
|
fd uintptr
|
||||||
|
lw string
|
||||||
|
locktype int16
|
||||||
|
}
|
||||||
|
|
||||||
|
// Lock locks the lock file
|
||||||
|
func (l *lockfile) Lock() {
|
||||||
|
lk := unix.Flock_t{
|
||||||
|
Type: l.locktype,
|
||||||
|
Whence: int16(os.SEEK_SET),
|
||||||
|
Start: 0,
|
||||||
|
Len: 0,
|
||||||
|
Pid: int32(os.Getpid()),
|
||||||
|
}
|
||||||
|
l.mu.Lock()
|
||||||
|
for unix.FcntlFlock(l.fd, unix.F_SETLKW, &lk) != nil {
|
||||||
|
time.Sleep(10 * time.Millisecond)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unlock unlocks the lock file
|
||||||
|
func (l *lockfile) Unlock() {
|
||||||
|
lk := unix.Flock_t{
|
||||||
|
Type: unix.F_UNLCK,
|
||||||
|
Whence: int16(os.SEEK_SET),
|
||||||
|
Start: 0,
|
||||||
|
Len: 0,
|
||||||
|
Pid: int32(os.Getpid()),
|
||||||
|
}
|
||||||
|
for unix.FcntlFlock(l.fd, unix.F_SETLKW, &lk) != nil {
|
||||||
|
time.Sleep(10 * time.Millisecond)
|
||||||
|
}
|
||||||
|
l.mu.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Touch updates the lock file with the UID of the user
|
||||||
|
func (l *lockfile) Touch() error {
|
||||||
|
l.lw = stringid.GenerateRandomID()
|
||||||
|
id := []byte(l.lw)
|
||||||
|
_, err := unix.Seek(int(l.fd), 0, os.SEEK_SET)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
n, err := unix.Write(int(l.fd), id)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if n != len(id) {
|
||||||
|
return unix.ENOSPC
|
||||||
|
}
|
||||||
|
err = unix.Fsync(int(l.fd))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Modified indicates if the lock file has been updated since the last time it was loaded
|
||||||
|
func (l *lockfile) Modified() (bool, error) {
|
||||||
|
id := []byte(l.lw)
|
||||||
|
_, err := unix.Seek(int(l.fd), 0, os.SEEK_SET)
|
||||||
|
if err != nil {
|
||||||
|
return true, err
|
||||||
|
}
|
||||||
|
n, err := unix.Read(int(l.fd), id)
|
||||||
|
if err != nil {
|
||||||
|
return true, err
|
||||||
|
}
|
||||||
|
if n != len(id) {
|
||||||
|
return true, unix.ENOSPC
|
||||||
|
}
|
||||||
|
lw := l.lw
|
||||||
|
l.lw = string(id)
|
||||||
|
return l.lw != lw, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsRWLock indicates if the lock file is a read-write lock
|
||||||
|
func (l *lockfile) IsReadWrite() bool {
|
||||||
|
return (l.locktype == unix.F_WRLCK)
|
||||||
|
}
|
40
vendor/github.com/containers/storage/lockfile_windows.go
generated
vendored
Normal file
40
vendor/github.com/containers/storage/lockfile_windows.go
generated
vendored
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
// +build windows
|
||||||
|
|
||||||
|
package storage
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func getLockFile(path string, ro bool) (Locker, error) {
|
||||||
|
return &lockfile{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type lockfile struct {
|
||||||
|
mu sync.Mutex
|
||||||
|
file string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *lockfile) Lock() {
|
||||||
|
}
|
||||||
|
func (l *lockfile) Unlock() {
|
||||||
|
}
|
||||||
|
func (l *lockfile) Modified() (bool, error) {
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
func (l *lockfile) Touch() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
func (l *lockfile) IsReadWrite() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *lockfile) TouchedSince(when time.Time) bool {
|
||||||
|
stat, err := os.Stat(l.file)
|
||||||
|
if err != nil {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return when.Before(stat.ModTime())
|
||||||
|
}
|
11
vendor/github.com/containers/storage/stat_mtim.go
generated
vendored
11
vendor/github.com/containers/storage/stat_mtim.go
generated
vendored
|
@ -1,11 +0,0 @@
|
||||||
// +build linux solaris
|
|
||||||
|
|
||||||
package storage
|
|
||||||
|
|
||||||
import (
|
|
||||||
"golang.org/x/sys/unix"
|
|
||||||
)
|
|
||||||
|
|
||||||
func statTMtimeUnix(st unix.Stat_t) (int64, int64) {
|
|
||||||
return st.Mtim.Unix()
|
|
||||||
}
|
|
11
vendor/github.com/containers/storage/stat_mtimespec.go
generated
vendored
11
vendor/github.com/containers/storage/stat_mtimespec.go
generated
vendored
|
@ -1,11 +0,0 @@
|
||||||
// +build !linux,!solaris
|
|
||||||
|
|
||||||
package storage
|
|
||||||
|
|
||||||
import (
|
|
||||||
"golang.org/x/sys/unix"
|
|
||||||
)
|
|
||||||
|
|
||||||
func statTMtimeUnix(st unix.Stat_t) (int64, int64) {
|
|
||||||
return st.Mtimespec.Unix()
|
|
||||||
}
|
|
Loading…
Reference in a new issue