@@ -27,6 +27,7 @@ import (
2727 "strconv"
2828 "strings"
2929
30+ "github.com/compose-spec/compose-go/v2/paths"
3031 "github.com/compose-spec/compose-go/v2/types"
3132 "github.com/docker/compose/v2/pkg/api"
3233 "github.com/docker/compose/v2/pkg/progress"
@@ -1126,28 +1127,22 @@ func isUnixAbs(p string) bool {
11261127}
11271128
11281129func isWindowsAbs (p string ) bool {
1129- if strings .HasPrefix (p , "\\ \\ " ) {
1130- return true
1131- }
1132- if len (p ) > 2 && p [1 ] == ':' {
1133- return p [2 ] == '\\'
1134- }
1135- return false
1130+ return paths .IsWindowsAbs (p )
11361131}
11371132
11381133func buildMount (project types.Project , volume types.ServiceVolumeConfig ) (mount.Mount , error ) {
11391134 source := volume .Source
1140- // on windows, filepath.IsAbs(source) is false for unix style abs path like /var/run/docker.sock.
1141- // do not replace these with filepath.Abs(source) that will include a default drive.
1142- if volume .Type == types .VolumeTypeBind && ! filepath .IsAbs (source ) && ! strings .HasPrefix (source , "/" ) {
1143- // volume source has already been prefixed with workdir if required, by compose-go project loader
1144- var err error
1145- source , err = filepath .Abs (source )
1146- if err != nil {
1147- return mount.Mount {}, err
1135+ switch volume .Type {
1136+ case types .VolumeTypeBind :
1137+ if ! filepath .IsAbs (source ) && ! isUnixAbs (source ) && ! isWindowsAbs (source ) {
1138+ // volume source has already been prefixed with workdir if required, by compose-go project loader
1139+ var err error
1140+ source , err = filepath .Abs (source )
1141+ if err != nil {
1142+ return mount.Mount {}, err
1143+ }
11481144 }
1149- }
1150- if volume .Type == types .VolumeTypeVolume {
1145+ case types .VolumeTypeVolume :
11511146 if volume .Source != "" {
11521147 pVolume , ok := project .Volumes [volume .Source ]
11531148 if ok {
0 commit comments