Use path.Join for server side path generation (#2689)

make sure to have valid config even when server is running under windows

---
*Sponsored by Kithara Software GmbH*
This commit is contained in:
6543 2023-11-01 11:29:44 +01:00 committed by GitHub
parent fe7dc3fff5
commit e83357833d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 7 deletions

View file

@ -18,7 +18,6 @@ import (
"fmt" "fmt"
"maps" "maps"
"path" "path"
"path/filepath"
"strings" "strings"
"github.com/google/uuid" "github.com/google/uuid"
@ -212,8 +211,8 @@ func (c *Compiler) createProcess(name string, container *yaml_types.Container, s
} }
func (c *Compiler) stepWorkdir(container *yaml_types.Container) string { func (c *Compiler) stepWorkdir(container *yaml_types.Container) string {
if filepath.IsAbs(container.Directory) { if path.IsAbs(container.Directory) {
return container.Directory return container.Directory
} }
return filepath.Join(c.base, c.path, container.Directory) return path.Join(c.base, c.path, container.Directory)
} }

View file

@ -16,7 +16,7 @@ package compiler
import ( import (
"net/url" "net/url"
"path/filepath" "path"
"strings" "strings"
"github.com/woodpecker-ci/woodpecker/pipeline/frontend/metadata" "github.com/woodpecker-ci/woodpecker/pipeline/frontend/metadata"
@ -105,12 +105,12 @@ func WithWorkspace(base, path string) Option {
// WithWorkspaceFromURL configures the compiler with the workspace // WithWorkspaceFromURL configures the compiler with the workspace
// base and path based on the repository url. // base and path based on the repository url.
func WithWorkspaceFromURL(base, link string) Option { func WithWorkspaceFromURL(base, link string) Option {
path := "src" srcPath := "src"
parsed, err := url.Parse(link) parsed, err := url.Parse(link)
if err == nil { if err == nil {
path = filepath.Join(path, parsed.Hostname(), parsed.Path) srcPath = path.Join(srcPath, parsed.Hostname(), parsed.Path)
} }
return WithWorkspace(base, path) return WithWorkspace(base, srcPath)
} }
// WithEscalated configures the compiler to automatically execute // WithEscalated configures the compiler to automatically execute