(token string, pathValue string, currentPath string, source fileStatProvider, preferRelative bool)
| 871 | } |
| 872 | |
| 873 | func expandRemotePatternToken(token string, pathValue string, currentPath string, source fileStatProvider, preferRelative bool) ([]string, error) { |
| 874 | if !hasWildcard(token) { |
| 875 | return []string{token}, nil |
| 876 | } |
| 877 | |
| 878 | basePath := currentPath |
| 879 | if strings.TrimSpace(pathValue) != "" { |
| 880 | basePath = pathValue |
| 881 | } |
| 882 | |
| 883 | patternPath := token |
| 884 | if !path.IsAbs(patternPath) { |
| 885 | patternPath = path.Clean(path.Join(basePath, patternPath)) |
| 886 | } else { |
| 887 | patternPath = path.Clean(patternPath) |
| 888 | } |
| 889 | |
| 890 | parentPath := path.Dir(patternPath) |
| 891 | if parentPath == "." { |
| 892 | parentPath = "/" |
| 893 | } |
| 894 | |
| 895 | matches, err := matchRemotePattern(source, parentPath, path.Base(patternPath)) |
| 896 | if err != nil { |
| 897 | return nil, err |
| 898 | } |
| 899 | if len(matches) == 0 { |
| 900 | return nil, fmt.Errorf("shell: no matches found for %s", token) |
| 901 | } |
| 902 | |
| 903 | if preferRelative && !path.IsAbs(token) && strings.TrimSpace(pathValue) != "" { |
| 904 | rewritten := make([]string, 0, len(matches)) |
| 905 | for _, match := range matches { |
| 906 | rewritten = append(rewritten, relativeRemotePath(pathValue, match)) |
| 907 | } |
| 908 | return rewritten, nil |
| 909 | } |
| 910 | |
| 911 | return matches, nil |
| 912 | } |
| 913 | |
| 914 | func matchRemotePattern(source fileStatProvider, parentPath string, pattern string) ([]string, error) { |
| 915 | parentID := "" |
no test coverage detected