Skip to content

Commit d09703e

Browse files
authored
Merge pull request moby#5452 from tonistiigi/ociindex-readonly-fix
ociindex: allow readonly access
2 parents 076d69e + 62e4130 commit d09703e

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)