Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support HTCondor's funky _ schemes #69

Merged
merged 4 commits into from
Jun 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,20 @@ func GetCachesFromNamespace(namespace Namespace) (caches []Cache, err error) {
return
}

func correctURLWithUnderscore(sourceFile string) (string, string) {
schemeIndex := strings.Index(sourceFile, "://")
if schemeIndex == -1 {
return sourceFile, ""
}

originalScheme := sourceFile[:schemeIndex]
if strings.Contains(originalScheme, "_") {
scheme := strings.ReplaceAll(originalScheme, "_", ".")
sourceFile = scheme + sourceFile[schemeIndex:]
}
return sourceFile, originalScheme
}

// Start the transfer, whether read or write back
func DoStashCPSingle(sourceFile string, destination string, methods []string, recursive bool) (bytesTransferred int64, err error) {

Expand All @@ -269,18 +283,21 @@ func DoStashCPSingle(sourceFile string, destination string, methods []string, re
}()

// Parse the source and destination with URL parse

sourceFile, source_scheme := correctURLWithUnderscore(sourceFile)
source_url, err := url.Parse(sourceFile)
if err != nil {
log.Errorln("Failed to parse source URL:", err)
return 0, err
}

source_url.Scheme = source_scheme

destination, dest_scheme := correctURLWithUnderscore(destination)
dest_url, err := url.Parse(destination)
if err != nil {
log.Errorln("Failed to parse destination URL:", err)
return 0, err
}
dest_url.Scheme = dest_scheme

// If there is a host specified, prepend it to the path
if source_url.Host != "" {
Expand Down
37 changes: 37 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,43 @@ func FuzzGetTokenName(f *testing.F) {
})
}

func TestCorrectURLWithUnderscore(t *testing.T) {
tests := []struct {
name string
url string
expectedURL string
expectedScheme string
}{
{
name: "LIGO URL with underscore",
url: "ligo_data://ligo.org/data/1",
expectedURL: "ligo.data://ligo.org/data/1",
expectedScheme: "ligo_data",
},
{
name: "URL without underscore",
url: "http://example.com",
expectedURL: "http://example.com",
expectedScheme: "http",
},
{
name: "URL with no scheme",
url: "example.com",
expectedURL: "example.com",
expectedScheme: "",
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
actualURL, actualScheme := correctURLWithUnderscore(tt.url)
if actualURL != tt.expectedURL || actualScheme != tt.expectedScheme {
t.Errorf("correctURLWithUnderscore(%v) = %v, %v; want %v, %v", tt.url, actualURL, actualScheme, tt.expectedURL, tt.expectedScheme)
}
})
}
}

func TestParseNoJobAd(t *testing.T) {
// Job ad file does not exist
tempDir := t.TempDir()
Expand Down