diff options
author | Christophe Fergeau <cfergeau@redhat.com> | 2022-07-25 17:10:27 +0200 |
---|---|---|
committer | Christophe Fergeau <cfergeau@redhat.com> | 2022-07-26 09:12:27 +0200 |
commit | 8e56a5605fbcd8c978308985e7f5b08dbdb948ee (patch) | |
tree | 1baa7482c19f1342395ad3573ef8d3ebb4c9d0c4 /pkg/machine/qemu | |
parent | e9d29d71cb3185fc071ba4d5f353c9eff6ff349a (diff) | |
download | podman-8e56a5605fbcd8c978308985e7f5b08dbdb948ee.tar.gz podman-8e56a5605fbcd8c978308985e7f5b08dbdb948ee.tar.bz2 podman-8e56a5605fbcd8c978308985e7f5b08dbdb948ee.zip |
machine: Fix check which is always true
Before making / mutable/immutable, podman-machine checks if the mount is
being done in /home or /mnt. However the current check is always going
to be true:
```
!strings.HasPrefix(mount.Target, "/home") || !strings.HasPrefix(mount.Target, "/mnt")
```
is false when mount.Target starts with "/home" and mount.Target starts
with "/mnt", which cannot happen at the same time.
The correct check is:
```
!strings.HasPrefix(mount.Target, "/home") && !strings.HasPrefix(mount.Target, "/mnt")
```
which can also be written as:
```
!(strings.HasPrefix(mount.Target, "/home") || strings.HasPrefix(mount.Target, "/mnt"))
```
The impact is not too bad, it results in extra 'chattr -i' calls which
should be unneeded.
[NO NEW TESTS NEEDED]
Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
Diffstat (limited to 'pkg/machine/qemu')
-rw-r--r-- | pkg/machine/qemu/machine.go | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/pkg/machine/qemu/machine.go b/pkg/machine/qemu/machine.go index 3b57455c4..7974c261e 100644 --- a/pkg/machine/qemu/machine.go +++ b/pkg/machine/qemu/machine.go @@ -670,11 +670,11 @@ func (v *MachineVM) Start(name string, _ machine.StartOptions) error { // because / is immutable, we have to monkey around with permissions // if we dont mount in /home or /mnt args := []string{"-q", "--"} - if !strings.HasPrefix(mount.Target, "/home") || !strings.HasPrefix(mount.Target, "/mnt") { + if !strings.HasPrefix(mount.Target, "/home") && !strings.HasPrefix(mount.Target, "/mnt") { args = append(args, "sudo", "chattr", "-i", "/", ";") } args = append(args, "sudo", "mkdir", "-p", mount.Target) - if !strings.HasPrefix(mount.Target, "/home") || !strings.HasPrefix(mount.Target, "/mnt") { + if !strings.HasPrefix(mount.Target, "/home") && !strings.HasPrefix(mount.Target, "/mnt") { args = append(args, ";", "sudo", "chattr", "+i", "/", ";") } err = v.SSH(name, machine.SSHOptions{Args: args}) |