Skip to content

Commit d889aeb

Browse files
committed
artifact: Skip AddLocal optimization on WSL
The local API path optimization is ineffective on WSL because of NTFS mounting overhead. Signed-off-by: Jan Rodák <[email protected]>
1 parent 2f7094c commit d889aeb

File tree

3 files changed

+42
-19
lines changed

3 files changed

+42
-19
lines changed

internal/localapi/utils.go

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -237,22 +237,34 @@ func CheckIfImageBuildPathsOnRunningMachine(ctx context.Context, containerFiles
237237
return translatedContainerFiles, options, true
238238
}
239239

240-
// IsHyperVProvider checks if the current machine provider is Hyper-V.
241-
// It returns true if the provider is Hyper-V, false otherwise, or an error if the check fails.
242-
func IsHyperVProvider(ctx context.Context) (bool, error) {
240+
func getVmProviderType(ctx context.Context) (define.VMType, error) {
243241
conn, err := bindings.GetClient(ctx)
244242
if err != nil {
245243
logrus.Debugf("Failed to get client connection: %v", err)
246-
return false, err
244+
return define.UnknownVirt, err
247245
}
248246

249247
_, vmProvider, err := FindMachineByPort(conn.URI.String(), conn.URI)
250248
if err != nil {
251249
logrus.Debugf("Failed to get machine hypervisor type: %v", err)
252-
return false, err
250+
return define.UnknownVirt, err
253251
}
254252

255-
return vmProvider.VMType() == define.HyperVVirt, nil
253+
return vmProvider.VMType(), nil
254+
}
255+
256+
// IsHyperVProvider checks if the current machine provider is Hyper-V.
257+
// It returns true if the provider is Hyper-V, false otherwise, or an error if the check fails.
258+
func IsHyperVProvider(ctx context.Context) (bool, error) {
259+
providerType, err := getVmProviderType(ctx)
260+
return providerType == define.HyperVVirt, err
261+
}
262+
263+
// IsWSLProvider checks if the current machine provider is WSL.
264+
// It returns true if the provider is WSL, false otherwise, or an error if the check fails.
265+
func IsWSLProvider(ctx context.Context) (bool, error) {
266+
providerType, err := getVmProviderType(ctx)
267+
return providerType == define.WSLVirt, err
256268
}
257269

258270
// ValidatePathForLocalAPI checks if the provided path satisfies requirements for local API usage.

internal/localapi/utils_unsupported.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ func IsHyperVProvider(ctx context.Context) (bool, error) {
2424
return false, nil
2525
}
2626

27+
func IsWSLProvider(ctx context.Context) (bool, error) {
28+
logrus.Debug("IsWSLProvider is not supported")
29+
return false, nil
30+
}
31+
2732
func ValidatePathForLocalAPI(path string) error {
2833
logrus.Debug("ValidatePathForLocalAPI is not supported")
2934
return nil

pkg/domain/infra/tunnel/artifact.go

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/containers/podman/v6/pkg/bindings/artifacts"
1313
"github.com/containers/podman/v6/pkg/domain/entities"
1414
"github.com/containers/podman/v6/pkg/errorhandling"
15+
"github.com/sirupsen/logrus"
1516
"go.podman.io/image/v5/types"
1617
)
1718

@@ -107,21 +108,26 @@ func (ir *ImageEngine) ArtifactAdd(_ context.Context, name string, artifactBlob
107108
options.WithAppend(true)
108109
}
109110

110-
var err error
111-
if localMap, ok := localapi.CheckPathOnRunningMachine(ir.ClientCtx, blob.BlobFilePath); ok {
112-
artifactAddReport, err = artifacts.AddLocal(ir.ClientCtx, name, blob.FileName, localMap.RemotePath, &options)
113-
if err == nil {
114-
continue
115-
}
116-
var errModel *errorhandling.ErrorModel
117-
if errors.As(err, &errModel) {
118-
switch errModel.ResponseCode {
119-
case http.StatusNotFound, http.StatusMethodNotAllowed:
120-
default:
111+
isWSL, err := localapi.IsWSLProvider(ir.ClientCtx)
112+
if err != nil {
113+
logrus.Debugf("IsWSLProvider check failed: %v", err)
114+
}
115+
if !isWSL {
116+
if localMap, ok := localapi.CheckPathOnRunningMachine(ir.ClientCtx, blob.BlobFilePath); ok {
117+
artifactAddReport, err = artifacts.AddLocal(ir.ClientCtx, name, blob.FileName, localMap.RemotePath, &options)
118+
if err == nil {
119+
continue
120+
}
121+
var errModel *errorhandling.ErrorModel
122+
if errors.As(err, &errModel) {
123+
switch errModel.ResponseCode {
124+
case http.StatusNotFound, http.StatusMethodNotAllowed:
125+
default:
126+
return nil, artifactAddErrorCleanup(ir.ClientCtx, i, name, err)
127+
}
128+
} else {
121129
return nil, artifactAddErrorCleanup(ir.ClientCtx, i, name, err)
122130
}
123-
} else {
124-
return nil, artifactAddErrorCleanup(ir.ClientCtx, i, name, err)
125131
}
126132
}
127133

0 commit comments

Comments
 (0)