Skip to content

Commit

Permalink
Merge pull request moby#5452 from tonistiigi/ociindex-readonly-fix
Browse files Browse the repository at this point in the history
ociindex: allow readonly access
  • Loading branch information
AkihiroSuda authored Oct 25, 2024
2 parents 076d69e + 62e4130 commit d09703e
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions client/ociindex/ociindex.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"io"
"os"
"path"
"syscall"

"github.com/gofrs/flock"
ocispecs "github.com/opencontainers/image-spec/specs-go/v1"
Expand Down Expand Up @@ -36,15 +37,18 @@ func (s StoreIndex) Read() (*ocispecs.Index, error) {
lock := flock.New(s.lockPath)
locked, err := lock.TryRLock()
if err != nil {
return nil, errors.Wrapf(err, "could not lock %s", s.lockPath)
}
if !locked {
return nil, errors.Errorf("could not lock %s", s.lockPath)
if !errors.Is(err, syscall.EPERM) && !errors.Is(err, syscall.EROFS) {
return nil, errors.Wrapf(err, "could not lock %s", s.lockPath)
}
} else {
if !locked {
return nil, errors.Errorf("could not lock %s", s.lockPath)
}
defer func() {
lock.Unlock()
os.RemoveAll(s.lockPath)
}()
}
defer func() {
lock.Unlock()
os.RemoveAll(s.lockPath)
}()

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

0 comments on commit d09703e

Please sign in to comment.