Skip to content

Commit 62e4130

Browse files
committed
ociindex: allow readonly access
If file lock can't be taken because of a permission or readonly error then assume that the index is immutable and locks are not needed. Writer side is unchanged as if lock would be skipped then the write is assumed to fail anyway. Signed-off-by: Tonis Tiigi <[email protected]>
1 parent 076d69e commit 62e4130

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

client/ociindex/ociindex.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"io"
66
"os"
77
"path"
8+
"syscall"
89

910
"github.com/gofrs/flock"
1011
ocispecs "github.com/opencontainers/image-spec/specs-go/v1"
@@ -36,15 +37,18 @@ func (s StoreIndex) Read() (*ocispecs.Index, error) {
3637
lock := flock.New(s.lockPath)
3738
locked, err := lock.TryRLock()
3839
if err != nil {
39-
return nil, errors.Wrapf(err, "could not lock %s", s.lockPath)
40-
}
41-
if !locked {
42-
return nil, errors.Errorf("could not lock %s", s.lockPath)
40+
if !errors.Is(err, syscall.EPERM) && !errors.Is(err, syscall.EROFS) {
41+
return nil, errors.Wrapf(err, "could not lock %s", s.lockPath)
42+
}
43+
} else {
44+
if !locked {
45+
return nil, errors.Errorf("could not lock %s", s.lockPath)
46+
}
47+
defer func() {
48+
lock.Unlock()
49+
os.RemoveAll(s.lockPath)
50+
}()
4351
}
44-
defer func() {
45-
lock.Unlock()
46-
os.RemoveAll(s.lockPath)
47-
}()
4852

4953
b, err := os.ReadFile(s.indexPath)
5054
if err != nil {

0 commit comments

Comments
 (0)