Skip to content

Commit 5aabbf6

Browse files
authored
Merge pull request #502 from byepolr/refactor-writable
Refactor Mount#Writable to be boolean pointer
2 parents 595ed4f + 70621ff commit 5aabbf6

File tree

4 files changed

+12
-6
lines changed

4 files changed

+12
-6
lines changed

pkg/hostagent/mount.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func (a *HostAgent) setupMount(ctx context.Context, m limayaml.Mount) (*mount, e
5252
Host: "127.0.0.1",
5353
Port: a.sshLocalPort,
5454
RemotePath: expanded,
55-
Readonly: !m.Writable,
55+
Readonly: !(*m.Writable),
5656
SSHFSAdditionalArgs: []string{"-o", sshfsOptions},
5757
}
5858
if err := rsf.Prepare(); err != nil {

pkg/limayaml/defaults.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,9 @@ func FillDefault(y, d, o *LimaYAML, filePath string) {
301301
if mount.SSHFS.FollowSymlinks != nil {
302302
mounts[i].SSHFS.FollowSymlinks = mount.SSHFS.FollowSymlinks
303303
}
304-
mounts[i].Writable = mount.Writable
304+
if mount.Writable != nil {
305+
mounts[i].Writable = mount.Writable
306+
}
305307
} else {
306308
location[mount.Location] = len(mounts)
307309
mounts = append(mounts, mount)
@@ -314,6 +316,9 @@ func FillDefault(y, d, o *LimaYAML, filePath string) {
314316
if mount.SSHFS.FollowSymlinks == nil {
315317
mount.SSHFS.FollowSymlinks = pointer.Bool(false)
316318
}
319+
if mount.Writable == nil {
320+
mount.Writable = pointer.Bool(false)
321+
}
317322
}
318323

319324
// Note: DNS lists are not combined; highest priority setting is picked

pkg/limayaml/defaults_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ func TestFillDefault(t *testing.T) {
116116

117117
expect := builtin
118118
expect.Mounts = y.Mounts
119+
expect.Mounts[0].Writable = pointer.Bool(false)
119120
expect.Mounts[0].SSHFS.FollowSymlinks = pointer.Bool(false)
120121
// Only missing Mounts field is Writable, and the default value is also the null value: false
121122

@@ -191,7 +192,7 @@ func TestFillDefault(t *testing.T) {
191192
Mounts: []Mount{
192193
{
193194
Location: "/var/log",
194-
Writable: false,
195+
Writable: pointer.Bool(false),
195196
},
196197
},
197198
Provision: []Provision{
@@ -303,7 +304,7 @@ func TestFillDefault(t *testing.T) {
303304
Mounts: []Mount{
304305
{
305306
Location: "/var/log",
306-
Writable: true,
307+
Writable: pointer.Bool(true),
307308
SSHFS: SSHFS{FollowSymlinks: pointer.Bool(true)},
308309
},
309310
},
@@ -360,7 +361,7 @@ func TestFillDefault(t *testing.T) {
360361

361362
// o.Mounts just makes d.Mounts[0] writable because the Location matches
362363
expect.Mounts = append(d.Mounts, y.Mounts...)
363-
expect.Mounts[0].Writable = true
364+
expect.Mounts[0].Writable = pointer.Bool(true)
364365
expect.Mounts[0].SSHFS.FollowSymlinks = pointer.Bool(true)
365366

366367
// o.Networks[1] is overriding the d.Networks[0].Lima entry for the "def0" interface

pkg/limayaml/limayaml.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ type File struct {
4444

4545
type Mount struct {
4646
Location string `yaml:"location" json:"location"` // REQUIRED
47-
Writable bool `yaml:"writable,omitempty" json:"writable,omitempty"`
47+
Writable *bool `yaml:"writable,omitempty" json:"writable,omitempty"`
4848
SSHFS SSHFS `yaml:"sshfs,omitempty" json:"sshfs,omitempty"`
4949
}
5050

0 commit comments

Comments
 (0)