Skip to content

Commit e430792

Browse files
Add ReadOnly() function
Signed-off-by: Gabriel Adrian Samfira <[email protected]>
1 parent 0277b9b commit e430792

2 files changed

Lines changed: 9 additions & 16 deletions

File tree

diff/windows/windows.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -335,15 +335,7 @@ func mountsToLayerAndParents(mounts []mount.Mount) (string, []string, error) {
335335
return "", nil, err
336336
}
337337

338-
isView := false
339-
for _, o := range mnt.Options {
340-
if o == "ro" {
341-
isView = true
342-
break
343-
}
344-
}
345-
346-
if isView {
338+
if mnt.ReadOnly() {
347339
if mnt.Type == "bind" && len(parentLayerPaths) != 0 {
348340
return "", nil, fmt.Errorf("unexpected bind-mount View with parents: %w", errdefs.ErrInvalidArgument)
349341
} else if mnt.Type == "bind" {

mount/mount_windows.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,19 @@ var (
3838
ErrNotImplementOnWindows = errors.New("not implemented under windows")
3939
)
4040

41-
// Mount to the provided target.
42-
func (m *Mount) mount(target string) (retErr error) {
43-
readOnly := false
41+
func (m *Mount) ReadOnly() bool {
4442
for _, option := range m.Options {
4543
if option == "ro" {
46-
readOnly = true
47-
break
44+
return true
4845
}
4946
}
47+
return false
48+
}
5049

50+
// Mount to the provided target.
51+
func (m *Mount) mount(target string) (retErr error) {
5152
if m.Type == "bind" {
52-
if err := bindfilter.ApplyFileBinding(target, m.Source, readOnly); err != nil {
53+
if err := bindfilter.ApplyFileBinding(target, m.Source, m.ReadOnly()); err != nil {
5354
return fmt.Errorf("failed to bind-mount to %s: %w", target, err)
5455
}
5556
return nil
@@ -98,7 +99,7 @@ func (m *Mount) mount(target string) (retErr error) {
9899
return fmt.Errorf("failed to get volume path for layer %s: %w", m.Source, err)
99100
}
100101

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

0 commit comments

Comments
 (0)