From d889aeb6af92e31fc4303dbae80edf81f688fdf4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Rod=C3=A1k?= Date: Wed, 19 Nov 2025 14:13:02 +0100 Subject: [PATCH] artifact: Skip AddLocal optimization on WSL MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The local API path optimization is ineffective on WSL because of NTFS mounting overhead. Signed-off-by: Jan Rodák --- internal/localapi/utils.go | 24 ++++++++++++++----- internal/localapi/utils_unsupported.go | 5 ++++ pkg/domain/infra/tunnel/artifact.go | 32 +++++++++++++++----------- 3 files changed, 42 insertions(+), 19 deletions(-) diff --git a/internal/localapi/utils.go b/internal/localapi/utils.go index c004272649..550787ffda 100644 --- a/internal/localapi/utils.go +++ b/internal/localapi/utils.go @@ -237,22 +237,34 @@ func CheckIfImageBuildPathsOnRunningMachine(ctx context.Context, containerFiles return translatedContainerFiles, options, true } -// IsHyperVProvider checks if the current machine provider is Hyper-V. -// It returns true if the provider is Hyper-V, false otherwise, or an error if the check fails. -func IsHyperVProvider(ctx context.Context) (bool, error) { +func getVmProviderType(ctx context.Context) (define.VMType, error) { conn, err := bindings.GetClient(ctx) if err != nil { logrus.Debugf("Failed to get client connection: %v", err) - return false, err + return define.UnknownVirt, err } _, vmProvider, err := FindMachineByPort(conn.URI.String(), conn.URI) if err != nil { logrus.Debugf("Failed to get machine hypervisor type: %v", err) - return false, err + return define.UnknownVirt, err } - return vmProvider.VMType() == define.HyperVVirt, nil + return vmProvider.VMType(), nil +} + +// IsHyperVProvider checks if the current machine provider is Hyper-V. +// It returns true if the provider is Hyper-V, false otherwise, or an error if the check fails. +func IsHyperVProvider(ctx context.Context) (bool, error) { + providerType, err := getVmProviderType(ctx) + return providerType == define.HyperVVirt, err +} + +// IsWSLProvider checks if the current machine provider is WSL. +// It returns true if the provider is WSL, false otherwise, or an error if the check fails. +func IsWSLProvider(ctx context.Context) (bool, error) { + providerType, err := getVmProviderType(ctx) + return providerType == define.WSLVirt, err } // ValidatePathForLocalAPI checks if the provided path satisfies requirements for local API usage. diff --git a/internal/localapi/utils_unsupported.go b/internal/localapi/utils_unsupported.go index 63b2d183cb..6880099e4e 100644 --- a/internal/localapi/utils_unsupported.go +++ b/internal/localapi/utils_unsupported.go @@ -24,6 +24,11 @@ func IsHyperVProvider(ctx context.Context) (bool, error) { return false, nil } +func IsWSLProvider(ctx context.Context) (bool, error) { + logrus.Debug("IsWSLProvider is not supported") + return false, nil +} + func ValidatePathForLocalAPI(path string) error { logrus.Debug("ValidatePathForLocalAPI is not supported") return nil diff --git a/pkg/domain/infra/tunnel/artifact.go b/pkg/domain/infra/tunnel/artifact.go index ba9a2d5daf..51d571de67 100644 --- a/pkg/domain/infra/tunnel/artifact.go +++ b/pkg/domain/infra/tunnel/artifact.go @@ -12,6 +12,7 @@ import ( "github.com/containers/podman/v6/pkg/bindings/artifacts" "github.com/containers/podman/v6/pkg/domain/entities" "github.com/containers/podman/v6/pkg/errorhandling" + "github.com/sirupsen/logrus" "go.podman.io/image/v5/types" ) @@ -107,21 +108,26 @@ func (ir *ImageEngine) ArtifactAdd(_ context.Context, name string, artifactBlob options.WithAppend(true) } - var err error - if localMap, ok := localapi.CheckPathOnRunningMachine(ir.ClientCtx, blob.BlobFilePath); ok { - artifactAddReport, err = artifacts.AddLocal(ir.ClientCtx, name, blob.FileName, localMap.RemotePath, &options) - if err == nil { - continue - } - var errModel *errorhandling.ErrorModel - if errors.As(err, &errModel) { - switch errModel.ResponseCode { - case http.StatusNotFound, http.StatusMethodNotAllowed: - default: + isWSL, err := localapi.IsWSLProvider(ir.ClientCtx) + if err != nil { + logrus.Debugf("IsWSLProvider check failed: %v", err) + } + if !isWSL { + if localMap, ok := localapi.CheckPathOnRunningMachine(ir.ClientCtx, blob.BlobFilePath); ok { + artifactAddReport, err = artifacts.AddLocal(ir.ClientCtx, name, blob.FileName, localMap.RemotePath, &options) + if err == nil { + continue + } + var errModel *errorhandling.ErrorModel + if errors.As(err, &errModel) { + switch errModel.ResponseCode { + case http.StatusNotFound, http.StatusMethodNotAllowed: + default: + return nil, artifactAddErrorCleanup(ir.ClientCtx, i, name, err) + } + } else { return nil, artifactAddErrorCleanup(ir.ClientCtx, i, name, err) } - } else { - return nil, artifactAddErrorCleanup(ir.ClientCtx, i, name, err) } }