diff --git a/cmd/octorpki/octorpki.go b/cmd/octorpki/octorpki.go index f14bbfd..a4b2d6b 100644 --- a/cmd/octorpki/octorpki.go +++ b/cmd/octorpki/octorpki.go @@ -349,15 +349,6 @@ func mustMkdirAll(fPath string) { } } -func mustExtractFilePathFromRsyncURL(rsyncURL string) string { - fPath, err := syncpki.ExtractFilePathFromRsyncURL(rsyncURL) - if err != nil { - log.Fatalf("Unable to extract file path from rsync url: %v", err) - } - - return fPath -} - func (s *OctoRPKI) ReceiveRRDPFileCallback(main string, url string, path string, data []byte, withdraw bool, snapshot bool, serial int64, args ...interface{}) error { if len(args) > 0 { rsync, ok := args[0].(string) @@ -547,6 +538,15 @@ func mustExtractFoldersPathFromRsyncURL(rsyncURL string) string { return downloadPath } +func mustExtractFilePathFromRsyncURL(rsyncURL string) string { + fPath, err := syncpki.ExtractFilePathFromRsyncURL(rsyncURL) + if err != nil { + log.Fatalf("Unable to extract file path from rsync url: %v", err) + } + + return fPath +} + func (s *OctoRPKI) fetchRsync(uri string, span opentracing.Span) { rSpan := s.tracer.StartSpan("sync", opentracing.ChildOf(span.Context())) defer rSpan.Finish() @@ -554,7 +554,7 @@ func (s *OctoRPKI) fetchRsync(uri string, span opentracing.Span) { rSpan.SetTag("type", "rsync") log.Infof("Rsync sync %v", uri) - downloadPath := mustExtractFoldersPathFromRsyncURL(uri) + downloadPath := mustExtractFilePathFromRsyncURL(uri) path := filepath.Join(*Basepath, downloadPath) ctxRsync, cancelRsync := context.WithTimeout(context.Background(), *RsyncTimeout) diff --git a/sync/lib/rsync.go b/sync/lib/rsync.go index c088cb3..030e595 100644 --- a/sync/lib/rsync.go +++ b/sync/lib/rsync.go @@ -27,12 +27,9 @@ func ExtractFoldersPathFromRsyncURL(url string) (string, error) { return "", fmt.Errorf("%q is not an rsync URL", url) } - fp := strings.Split(strings.TrimPrefix(url, RsyncProtoPrefix), "/") - if wantedFileExtensionRE.Match([]byte(fp[len(fp)-1])) { - fp = fp[:len(fp)-1] - } - - return strings.Join(fp, "/"), nil + filePath := strings.TrimPrefix(url, RsyncProtoPrefix) + parts := strings.Split(filePath, "/") + return strings.Join(parts[0:len(parts)-1], "/"), nil } func ExtractFilePathFromRsyncURL(url string) (string, error) { diff --git a/sync/lib/rsync_test.go b/sync/lib/rsync_test.go index f3fd08a..2acd0c2 100644 --- a/sync/lib/rsync_test.go +++ b/sync/lib/rsync_test.go @@ -15,7 +15,7 @@ func TestExtractFoldersPathFromRsyncURL(t *testing.T) { }{ { name: "Valid URL", - url: "rsync://r.magellan.ipxo.com/repo", + url: "rsync://r.magellan.ipxo.com/repo/foo", wantFail: false, expected: "r.magellan.ipxo.com/repo", }, @@ -24,12 +24,6 @@ func TestExtractFoldersPathFromRsyncURL(t *testing.T) { url: "xxxx://r.magellan.ipxo.com/repo", wantFail: true, }, - { - name: "Valid URL with file", - url: "rsync://r.magellan.ipxo.com/repo/foo.roa", - wantFail: false, - expected: "r.magellan.ipxo.com/repo", - }, } for _, test := range tests {