Skip to content
This repository has been archived by the owner on Jun 9, 2024. It is now read-only.

Commit

Permalink
rsync: Fix path extraction (now for real) (#140)
Browse files Browse the repository at this point in the history
Co-authored-by: Oliver Geiselhardt-Herms <[email protected]>
  • Loading branch information
takt and Oliver Geiselhardt-Herms authored Apr 19, 2023
1 parent 73c9cc2 commit 8b084e4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 23 deletions.
20 changes: 10 additions & 10 deletions cmd/octorpki/octorpki.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -547,14 +538,23 @@ 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()
rSpan.SetTag("rsync", uri)
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)
Expand Down
9 changes: 3 additions & 6 deletions sync/lib/rsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
8 changes: 1 addition & 7 deletions sync/lib/rsync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
Expand All @@ -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 {
Expand Down

0 comments on commit 8b084e4

Please sign in to comment.