Skip to content

Commit 331bd2d

Browse files
authored
Merge pull request #4046 from jandubois/mountpoints
Merge mounts in FillDefault based on mountPoint instead of location
2 parents 7e0da1e + ac04c69 commit 331bd2d

File tree

1 file changed

+22
-24
lines changed

1 file changed

+22
-24
lines changed

pkg/limayaml/defaults.go

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -631,21 +631,39 @@ func FillDefault(ctx context.Context, y, d, o *limatype.LimaYAML, filePath strin
631631
// Combine all mounts; highest priority entry determines writable status.
632632
// Only works for exact matches; does not normalize case or resolve symlinks.
633633
mounts := make([]limatype.Mount, 0, len(d.Mounts)+len(y.Mounts)+len(o.Mounts))
634-
location := make(map[string]int)
634+
mountPoint := make(map[string]int)
635635
for _, mount := range slices.Concat(d.Mounts, y.Mounts, o.Mounts) {
636636
if out, err := executeHostTemplate(mount.Location, instDir, y.Param); err == nil {
637637
mount.Location = filepath.Clean(out.String())
638638
} else {
639639
logrus.WithError(err).Warnf("Couldn't process mount location %q as a template", mount.Location)
640640
}
641-
if mount.MountPoint != nil {
641+
// Expand a path that begins with `~`. Relative paths are not modified, and rejected by Validate() later.
642+
if localpathutil.IsTildePath(mount.Location) {
643+
if location, err := localpathutil.Expand(mount.Location); err == nil {
644+
mount.Location = location
645+
} else {
646+
logrus.WithError(err).Warnf("Couldn't expand location %q", mount.Location)
647+
}
648+
}
649+
if mount.MountPoint == nil {
650+
mountLocation := mount.Location
651+
if runtime.GOOS == "windows" {
652+
var err error
653+
mountLocation, err = ioutilx.WindowsSubsystemPath(ctx, mountLocation)
654+
if err != nil {
655+
logrus.WithError(err).Warnf("Couldn't convert location %q into mount target", mount.Location)
656+
}
657+
}
658+
mount.MountPoint = ptr.Of(mountLocation)
659+
} else {
642660
if out, err := executeGuestTemplate(*mount.MountPoint, instDir, y.User, y.Param); err == nil {
643661
mount.MountPoint = ptr.Of(out.String())
644662
} else {
645663
logrus.WithError(err).Warnf("Couldn't process mount point %q as a template", *mount.MountPoint)
646664
}
647665
}
648-
if i, ok := location[mount.Location]; ok {
666+
if i, ok := mountPoint[*mount.MountPoint]; ok {
649667
if mount.SSHFS.Cache != nil {
650668
mounts[i].SSHFS.Cache = mount.SSHFS.Cache
651669
}
@@ -677,7 +695,7 @@ func FillDefault(ctx context.Context, y, d, o *limatype.LimaYAML, filePath strin
677695
mounts[i].MountPoint = mount.MountPoint
678696
}
679697
} else {
680-
location[mount.Location] = len(mounts)
698+
mountPoint[*mount.MountPoint] = len(mounts)
681699
mounts = append(mounts, mount)
682700
}
683701
}
@@ -713,26 +731,6 @@ func FillDefault(ctx context.Context, y, d, o *limatype.LimaYAML, filePath strin
713731
mounts[i].NineP.Cache = ptr.Of(Default9pCacheForRO)
714732
}
715733
}
716-
717-
// Expand a path that begins with `~`. Relative paths are not modified, and rejected by Validate() later.
718-
if localpathutil.IsTildePath(mount.Location) {
719-
if location, err := localpathutil.Expand(mount.Location); err == nil {
720-
mounts[i].Location = location
721-
} else {
722-
logrus.WithError(err).Warnf("Couldn't expand location %q", mount.Location)
723-
}
724-
}
725-
if mount.MountPoint == nil {
726-
mountLocation := mounts[i].Location
727-
if runtime.GOOS == "windows" {
728-
var err error
729-
mountLocation, err = ioutilx.WindowsSubsystemPath(ctx, mountLocation)
730-
if err != nil {
731-
logrus.WithError(err).Warnf("Couldn't convert location %q into mount target", mounts[i].Location)
732-
}
733-
}
734-
mounts[i].MountPoint = ptr.Of(mountLocation)
735-
}
736734
}
737735

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

0 commit comments

Comments
 (0)