Skip to content

Commit

Permalink
Add ReadOnly() function
Browse files Browse the repository at this point in the history
Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
  • Loading branch information
gabriel-samfira committed May 30, 2023
1 parent 0277b9b commit e430792
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 16 deletions.
10 changes: 1 addition & 9 deletions diff/windows/windows.go
Expand Up @@ -335,15 +335,7 @@ func mountsToLayerAndParents(mounts []mount.Mount) (string, []string, error) {
return "", nil, err
}

isView := false
for _, o := range mnt.Options {
if o == "ro" {
isView = true
break
}
}

if isView {
if mnt.ReadOnly() {
if mnt.Type == "bind" && len(parentLayerPaths) != 0 {
return "", nil, fmt.Errorf("unexpected bind-mount View with parents: %w", errdefs.ErrInvalidArgument)
} else if mnt.Type == "bind" {
Expand Down
15 changes: 8 additions & 7 deletions mount/mount_windows.go
Expand Up @@ -38,18 +38,19 @@ var (
ErrNotImplementOnWindows = errors.New("not implemented under windows")
)

// Mount to the provided target.
func (m *Mount) mount(target string) (retErr error) {
readOnly := false
func (m *Mount) ReadOnly() bool {
for _, option := range m.Options {
if option == "ro" {
readOnly = true
break
return true
}
}
return false
}

// Mount to the provided target.
func (m *Mount) mount(target string) (retErr error) {
if m.Type == "bind" {
if err := bindfilter.ApplyFileBinding(target, m.Source, readOnly); err != nil {
if err := bindfilter.ApplyFileBinding(target, m.Source, m.ReadOnly()); err != nil {
return fmt.Errorf("failed to bind-mount to %s: %w", target, err)
}
return nil
Expand Down Expand Up @@ -98,7 +99,7 @@ func (m *Mount) mount(target string) (retErr error) {
return fmt.Errorf("failed to get volume path for layer %s: %w", m.Source, err)
}

if err := bindfilter.ApplyFileBinding(target, volume, readOnly); err != nil {
if err := bindfilter.ApplyFileBinding(target, volume, m.ReadOnly()); err != nil {
return fmt.Errorf("failed to set volume mount path for layer %s: %w", m.Source, err)
}
defer func() {
Expand Down

0 comments on commit e430792

Please sign in to comment.