mirror of
https://github.com/containers/podman.git
synced 2025-08-01 04:42:20 +08:00

There are 2 things added. First there is added support for handling drive letters while doing value split. If drive letter is detected, then max number of elements will be increased by one, but then first two will be concatenated to reconstruct the path. Second part is basic, but working, conversion of Windows path to Unix path to be used, when target path is not explicitly specified. Signed-off-by: Arthur Sengileyev <arthur.sengileyev@gmail.com>
53 lines
1.3 KiB
Go
53 lines
1.3 KiB
Go
package qemu
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
"regexp"
|
|
"strings"
|
|
|
|
"github.com/containers/podman/v4/pkg/machine"
|
|
)
|
|
|
|
func isProcessAlive(pid int) bool {
|
|
if checkProcessStatus("process", pid, nil) == nil {
|
|
return true
|
|
}
|
|
return false
|
|
}
|
|
|
|
func checkProcessStatus(processHint string, pid int, stderrBuf *bytes.Buffer) error {
|
|
active, exitCode := machine.GetProcessState(pid)
|
|
if !active {
|
|
if stderrBuf != nil {
|
|
return fmt.Errorf("%s exited unexpectedly, exit code: %d stderr: %s", processHint, exitCode, stderrBuf.String())
|
|
} else {
|
|
return fmt.Errorf("%s exited unexpectedly, exit code: %d", processHint, exitCode)
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func pathsFromVolume(volume string) []string {
|
|
paths := strings.SplitN(volume, ":", 3)
|
|
driveLetterMatcher := regexp.MustCompile(`^(?:\\\\[.?]\\)?[a-zA-Z]$`)
|
|
if len(paths) > 1 && driveLetterMatcher.MatchString(paths[0]) {
|
|
paths = strings.SplitN(volume, ":", 4)
|
|
paths = append([]string{paths[0] + ":" + paths[1]}, paths[2:]...)
|
|
}
|
|
return paths
|
|
}
|
|
|
|
func extractTargetPath(paths []string) string {
|
|
if len(paths) > 1 {
|
|
return paths[1]
|
|
}
|
|
target := strings.ReplaceAll(paths[0], "\\", "/")
|
|
target = strings.ReplaceAll(target, ":", "/")
|
|
if strings.HasPrefix(target, "//./") || strings.HasPrefix(target, "//?/") {
|
|
target = target[4:]
|
|
}
|
|
dedup := regexp.MustCompile(`//+`)
|
|
return dedup.ReplaceAllLiteralString("/"+target, "/")
|
|
}
|