fix issue

Signed-off-by: yxxhero <aiopsclub@163.com>
This commit is contained in:
yxxhero 2024-02-11 20:42:45 +08:00
parent 4cfe522f4f
commit 7696c03c25
1 changed files with 12 additions and 8 deletions

View File

@ -124,13 +124,17 @@ func Parse(goGetterSrc string) (*Source, error) {
return nil, InvalidURLError{err: fmt.Sprintf("parse url: missing scheme - probably this is a local file path? %s", goGetterSrc)}
}
var sourceDir, sourceFile string
pathComponents := strings.Split(u.Path, "@")
if len(pathComponents) != 2 {
dir := filepath.Dir(u.Path)
if len(dir) > 0 {
dir = dir[1:]
}
pathComponents = []string{dir, filepath.Base(u.Path)}
switch len(pathComponents) {
case 1:
sourceDir = pathComponents[0]
case 2:
sourceDir = pathComponents[0]
sourceFile = pathComponents[1]
default:
return nil, InvalidURLError{err: fmt.Sprintf("parse url: invalid path %s", u.Path)}
}
return &Source{
@ -138,8 +142,8 @@ func Parse(goGetterSrc string) (*Source, error) {
User: u.User.String(),
Scheme: u.Scheme,
Host: u.Host,
Dir: pathComponents[0],
File: pathComponents[1],
Dir: sourceDir,
File: sourceFile,
RawQuery: u.RawQuery,
}, nil
}