Semi force the umount of oem when dealing with mounts (#40)

This commit is contained in:
Itxaka 2023-08-07 16:35:15 +02:00 committed by GitHub
parent 396c5553ca
commit 7203787534
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 8 deletions

View File

@ -35,14 +35,11 @@ func addCloudConfig(cloudConfig, filename string) error {
func writeCloudConfig(oem state.PartitionState, cloudConfig, subpath, filename string) error {
mountPath := "/tmp/oem"
defer mounts.Umount(state.PartitionState{Mounted: true, MountPoint: mountPath}) //nolint:errcheck
if err := mounts.PrepareWrite(oem, mountPath); err != nil {
return err
}
defer func() {
oem.MountPoint = mountPath
mounts.Umount(oem) //nolint:errcheck
}()
_ = os.MkdirAll(filepath.Join(mountPath, subpath), 0650)
return os.WriteFile(filepath.Join(mountPath, subpath, fmt.Sprintf("%s.yaml", filename)), []byte(cloudConfig), 0650)
}

View File

@ -19,6 +19,7 @@ func SetGRUBOptions(opts map[string]string) Option {
func setGRUBOptions(opts map[string]string) error {
mountPath := "/tmp/oem"
defer mounts.Umount(state.PartitionState{Mounted: true, MountPoint: mountPath}) //nolint:errcheck
runtime, err := state.NewRuntime()
if err != nil {
return err
@ -32,10 +33,6 @@ func setGRUBOptions(opts map[string]string) error {
if err := mounts.PrepareWrite(oem, mountPath); err != nil {
return err
}
defer func() {
oem.MountPoint = mountPath
mounts.Umount(oem) //nolint:errcheck
}()
for k, v := range opts {
out, err := utils.SH(fmt.Sprintf(`%s /tmp/oem/grubenv set "%s=%s"`, utils.FindCommand("grub2-editenv", []string{"grub2-editenv", "grub-editenv"}), k, v))