summaryrefslogtreecommitdiff
path: root/pkg/specgen
diff options
context:
space:
mode:
authorCharlie Doern <cdoern@redhat.com>2022-06-21 15:41:10 -0400
committerCharlie Doern <cdoern@redhat.com>2022-06-22 16:52:16 -0400
commit2eda547dcd597a23ecc2311a7ceca46746a3026e (patch)
tree068c500c04fefe561f38f6d5232f4b0c8eaa636b /pkg/specgen
parent2382955c6a88e506ce6d85477c8c68bd24859bdd (diff)
downloadpodman-2eda547dcd597a23ecc2311a7ceca46746a3026e.tar.gz
podman-2eda547dcd597a23ecc2311a7ceca46746a3026e.tar.bz2
podman-2eda547dcd597a23ecc2311a7ceca46746a3026e.zip
podman run/create -v relative filepath support
podman currently does not support relative volume paths. Add parsing for relative paths in specgen, converting whatever volume was given to an absolute path. Signed-off-by: Charlie Doern <cdoern@redhat.com>
Diffstat (limited to 'pkg/specgen')
-rw-r--r--pkg/specgen/volumes.go16
1 files changed, 15 insertions, 1 deletions
diff --git a/pkg/specgen/volumes.go b/pkg/specgen/volumes.go
index a7a1022b0..f272a5c11 100644
--- a/pkg/specgen/volumes.go
+++ b/pkg/specgen/volumes.go
@@ -1,6 +1,7 @@
package specgen
import (
+ "path/filepath"
"strings"
"github.com/containers/common/pkg/parse"
@@ -56,7 +57,6 @@ func GenVolumeMounts(volumeFlag []string) (map[string]spec.Mount, map[string]*Na
overlayVolumes := make(map[string]*OverlayVolume)
volumeFormatErr := errors.Errorf("incorrect volume format, should be [host-dir:]ctr-dir[:option]")
-
for _, vol := range volumeFlag {
var (
options []string
@@ -71,6 +71,20 @@ func GenVolumeMounts(volumeFlag []string) (map[string]spec.Mount, map[string]*Na
}
src = splitVol[0]
+
+ // Support relative paths beginning with ./
+ if strings.HasPrefix(src, "./") {
+ path, err := filepath.EvalSymlinks(src)
+ if err != nil {
+ return nil, nil, nil, err
+ }
+ src, err = filepath.Abs(path)
+ if err != nil {
+ return nil, nil, nil, err
+ }
+ splitVol[0] = src
+ }
+
if len(splitVol) == 1 {
// This is an anonymous named volume. Only thing given
// is destination.