From d430668af6d59985508dc27f35e0b952df2cea89 Mon Sep 17 00:00:00 2001 From: Gergely Brautigam <182850+Skarlso@users.noreply.github.com> Date: Fri, 6 Dec 2024 17:25:37 +0100 Subject: [PATCH] fix: replace juju with rogpeppe go internal Signed-off-by: Gergely Brautigam <182850+Skarlso@users.noreply.github.com> --- api/utils/filelock/lock.go | 30 ++++++++++++++++-------------- go.mod | 2 +- go.sum | 2 -- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/api/utils/filelock/lock.go b/api/utils/filelock/lock.go index 4fe4ce641f..b015de5841 100644 --- a/api/utils/filelock/lock.go +++ b/api/utils/filelock/lock.go @@ -5,11 +5,10 @@ import ( "os" "sync" - "github.com/juju/fslock" "github.com/mandelsoft/filepath/pkg/filepath" - "github.com/mandelsoft/goutils/errors" "github.com/mandelsoft/vfs/pkg/osfs" "github.com/mandelsoft/vfs/pkg/vfs" + fslock "github.com/rogpeppe/go-internal/lockedfile" ) const DIRECTORY_LOCK = ".lock" @@ -25,19 +24,22 @@ const DIRECTORY_LOCK = ".lock" type Mutex struct { lock sync.Mutex path string - lockfile *fslock.Lock + lockfile *fslock.Mutex + unlock func() } func (m *Mutex) Lock() (io.Closer, error) { m.lock.Lock() if m.lockfile == nil { - m.lockfile = fslock.New(m.path) + m.lockfile = fslock.MutexAt(m.path) } - err := m.lockfile.Lock() + unlock, err := m.lockfile.Lock() if err != nil { m.lock.Unlock() return nil, err } + m.unlock = unlock + return &lock{mutex: m}, nil } @@ -46,16 +48,15 @@ func (m *Mutex) TryLock() (io.Closer, error) { return nil, nil } if m.lockfile == nil { - m.lockfile = fslock.New(m.path) + m.lockfile = fslock.MutexAt(m.path) } - err := m.lockfile.TryLock() + unlock, err := m.lockfile.Lock() if err != nil { m.lock.Unlock() - if errors.Is(err, fslock.ErrLocked) { - err = nil - } return nil, err } + m.unlock = unlock + return &lock{mutex: m}, nil } @@ -75,14 +76,15 @@ func (l *lock) Close() error { if l.mutex == nil { return os.ErrClosed } - l.mutex.lockfile.Unlock() + + l.mutex.unlock() l.mutex.lock.Unlock() l.mutex = nil return nil } var ( - _filelocks = map[string]*Mutex{} + _fileLocks = map[string]*Mutex{} _lock sync.Mutex ) @@ -121,12 +123,12 @@ func MutexFor(path string) (*Mutex, error) { _lock.Lock() defer _lock.Unlock() - mutex := _filelocks[file] + mutex := _fileLocks[file] if mutex == nil { mutex = &Mutex{ path: file, } - _filelocks[file] = mutex + _fileLocks[file] = mutex } return mutex, nil } diff --git a/go.mod b/go.mod index ce8145cef0..dc01988860 100644 --- a/go.mod +++ b/go.mod @@ -38,7 +38,6 @@ require ( github.com/golang/mock v1.6.0 github.com/google/go-github/v45 v45.2.0 github.com/hashicorp/vault-client-go v0.4.3 - github.com/juju/fslock v0.0.0-20160525022230-4d5c94c67b4b github.com/klauspost/compress v1.17.11 github.com/klauspost/pgzip v1.2.6 github.com/mandelsoft/filepath v0.0.0-20240223090642-3e2777258aa3 @@ -57,6 +56,7 @@ require ( github.com/opencontainers/image-spec v1.1.0 github.com/pkg/errors v0.9.1 github.com/redis/go-redis/v9 v9.7.0 + github.com/rogpeppe/go-internal v1.13.1 github.com/sigstore/cosign/v2 v2.4.1 github.com/sigstore/rekor v1.3.7 github.com/sigstore/sigstore v1.8.10 diff --git a/go.sum b/go.sum index e6fda21192..eb3fdb47a3 100644 --- a/go.sum +++ b/go.sum @@ -657,8 +657,6 @@ github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/ github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= -github.com/juju/fslock v0.0.0-20160525022230-4d5c94c67b4b h1:FQ7+9fxhyp82ks9vAuyPzG0/vVbWwMwLJ+P6yJI5FN8= -github.com/juju/fslock v0.0.0-20160525022230-4d5c94c67b4b/go.mod h1:HMcgvsgd0Fjj4XXDkbjdmlbI505rUPBs6WBMYg2pXks= github.com/juju/loggo v0.0.0-20190526231331-6e530bcce5d8/go.mod h1:vgyd7OREkbtVEN/8IXZe5Ooef3LQePvuBm9UWj6ZL8U= github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=