Repository: lima-vm/lima
Pull request #502 (2021-12-29 14:46:43)

Refactor Mount#Writable to be boolean pointer
Signed-off-by: Jason W. Ehrlich <jwehrlich@outlook.com>


Patch:
diff --git a/pkg/hostagent/mount.go b/pkg/hostagent/mount.go
index f13461c8..57fa2c57 100644
--- a/pkg/hostagent/mount.go
+++ b/pkg/hostagent/mount.go
@@ -52,7 +52,7 @@ func (a *HostAgent) setupMount(ctx context.Context, m limayaml.Mount) (*mount, e
 		Host:                "127.0.0.1",
 		Port:                a.sshLocalPort,
 		RemotePath:          expanded,
-		Readonly:            !m.Writable,
+		Readonly:            !(*m.Writable),
 		SSHFSAdditionalArgs: []string{"-o", sshfsOptions},
 	}
 	if err := rsf.Prepare(); err != nil {
diff --git a/pkg/limayaml/defaults.go b/pkg/limayaml/defaults.go
index ffc96b91..74aba85f 100644
--- a/pkg/limayaml/defaults.go
+++ b/pkg/limayaml/defaults.go
@@ -301,7 +301,9 @@ func FillDefault(y, d, o *LimaYAML, filePath string) {
 			if mount.SSHFS.FollowSymlinks != nil {
 				mounts[i].SSHFS.FollowSymlinks = mount.SSHFS.FollowSymlinks
 			}
-			mounts[i].Writable = mount.Writable
+			if mount.Writable != nil {
+				mounts[i].Writable = mount.Writable
+			}
 		} else {
 			location[mount.Location] = len(mounts)
 			mounts = append(mounts, mount)
@@ -314,6 +316,9 @@ func FillDefault(y, d, o *LimaYAML, filePath string) {
 		if mount.SSHFS.FollowSymlinks == nil {
 			mount.SSHFS.FollowSymlinks = pointer.Bool(false)
 		}
+		if mount.Writable == nil {
+			mount.Writable = pointer.Bool(false)
+		}
 	}
 
 	// Note: DNS lists are not combined; highest priority setting is picked
diff --git a/pkg/limayaml/limayaml.go b/pkg/limayaml/limayaml.go
index 01118de1..20e33d36 100644
--- a/pkg/limayaml/limayaml.go
+++ b/pkg/limayaml/limayaml.go
@@ -44,7 +44,7 @@ type File struct {
 
 type Mount struct {
 	Location string `yaml:"location" json:"location"` // REQUIRED
-	Writable bool   `yaml:"writable,omitempty" json:"writable,omitempty"`
+	Writable *bool  `yaml:"writable,omitempty" json:"writable,omitempty"`
 	SSHFS    SSHFS  `yaml:"sshfs,omitempty" json:"sshfs,omitempty"`
 }
 


Test patch:
diff --git a/pkg/limayaml/defaults_test.go b/pkg/limayaml/defaults_test.go
index e1939dab..f6ca06b6 100644
--- a/pkg/limayaml/defaults_test.go
+++ b/pkg/limayaml/defaults_test.go
@@ -116,6 +116,7 @@ func TestFillDefault(t *testing.T) {
 
 	expect := builtin
 	expect.Mounts = y.Mounts
+	expect.Mounts[0].Writable = pointer.Bool(false)
 	expect.Mounts[0].SSHFS.FollowSymlinks = pointer.Bool(false)
 	// Only missing Mounts field is Writable, and the default value is also the null value: false
 
@@ -191,7 +192,7 @@ func TestFillDefault(t *testing.T) {
 		Mounts: []Mount{
 			{
 				Location: "/var/log",
-				Writable: false,
+				Writable: pointer.Bool(false),
 			},
 		},
 		Provision: []Provision{
@@ -303,7 +304,7 @@ func TestFillDefault(t *testing.T) {
 		Mounts: []Mount{
 			{
 				Location: "/var/log",
-				Writable: true,
+				Writable: pointer.Bool(true),
 				SSHFS:    SSHFS{FollowSymlinks: pointer.Bool(true)},
 			},
 		},
@@ -360,7 +361,7 @@ func TestFillDefault(t *testing.T) {
 
 	// o.Mounts just makes d.Mounts[0] writable because the Location matches
 	expect.Mounts = append(d.Mounts, y.Mounts...)
-	expect.Mounts[0].Writable = true
+	expect.Mounts[0].Writable = pointer.Bool(true)
 	expect.Mounts[0].SSHFS.FollowSymlinks = pointer.Bool(true)
 
 	// o.Networks[1] is overriding the d.Networks[0].Lima entry for the "def0" interface