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

Commit 8b084e4

Browse files
taktOliver Geiselhardt-Herms
andauthored
rsync: Fix path extraction (now for real) (#140)
Co-authored-by: Oliver Geiselhardt-Herms <[email protected]>
1 parent 73c9cc2 commit 8b084e4

File tree

3 files changed

+14
-23
lines changed

3 files changed

+14
-23
lines changed

cmd/octorpki/octorpki.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -349,15 +349,6 @@ func mustMkdirAll(fPath string) {
349349
}
350350
}
351351

352-
func mustExtractFilePathFromRsyncURL(rsyncURL string) string {
353-
fPath, err := syncpki.ExtractFilePathFromRsyncURL(rsyncURL)
354-
if err != nil {
355-
log.Fatalf("Unable to extract file path from rsync url: %v", err)
356-
}
357-
358-
return fPath
359-
}
360-
361352
func (s *OctoRPKI) ReceiveRRDPFileCallback(main string, url string, path string, data []byte, withdraw bool, snapshot bool, serial int64, args ...interface{}) error {
362353
if len(args) > 0 {
363354
rsync, ok := args[0].(string)
@@ -547,14 +538,23 @@ func mustExtractFoldersPathFromRsyncURL(rsyncURL string) string {
547538
return downloadPath
548539
}
549540

541+
func mustExtractFilePathFromRsyncURL(rsyncURL string) string {
542+
fPath, err := syncpki.ExtractFilePathFromRsyncURL(rsyncURL)
543+
if err != nil {
544+
log.Fatalf("Unable to extract file path from rsync url: %v", err)
545+
}
546+
547+
return fPath
548+
}
549+
550550
func (s *OctoRPKI) fetchRsync(uri string, span opentracing.Span) {
551551
rSpan := s.tracer.StartSpan("sync", opentracing.ChildOf(span.Context()))
552552
defer rSpan.Finish()
553553
rSpan.SetTag("rsync", uri)
554554
rSpan.SetTag("type", "rsync")
555555

556556
log.Infof("Rsync sync %v", uri)
557-
downloadPath := mustExtractFoldersPathFromRsyncURL(uri)
557+
downloadPath := mustExtractFilePathFromRsyncURL(uri)
558558

559559
path := filepath.Join(*Basepath, downloadPath)
560560
ctxRsync, cancelRsync := context.WithTimeout(context.Background(), *RsyncTimeout)

sync/lib/rsync.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,9 @@ func ExtractFoldersPathFromRsyncURL(url string) (string, error) {
2727
return "", fmt.Errorf("%q is not an rsync URL", url)
2828
}
2929

30-
fp := strings.Split(strings.TrimPrefix(url, RsyncProtoPrefix), "/")
31-
if wantedFileExtensionRE.Match([]byte(fp[len(fp)-1])) {
32-
fp = fp[:len(fp)-1]
33-
}
34-
35-
return strings.Join(fp, "/"), nil
30+
filePath := strings.TrimPrefix(url, RsyncProtoPrefix)
31+
parts := strings.Split(filePath, "/")
32+
return strings.Join(parts[0:len(parts)-1], "/"), nil
3633
}
3734

3835
func ExtractFilePathFromRsyncURL(url string) (string, error) {

sync/lib/rsync_test.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ func TestExtractFoldersPathFromRsyncURL(t *testing.T) {
1515
}{
1616
{
1717
name: "Valid URL",
18-
url: "rsync://r.magellan.ipxo.com/repo",
18+
url: "rsync://r.magellan.ipxo.com/repo/foo",
1919
wantFail: false,
2020
expected: "r.magellan.ipxo.com/repo",
2121
},
@@ -24,12 +24,6 @@ func TestExtractFoldersPathFromRsyncURL(t *testing.T) {
2424
url: "xxxx://r.magellan.ipxo.com/repo",
2525
wantFail: true,
2626
},
27-
{
28-
name: "Valid URL with file",
29-
url: "rsync://r.magellan.ipxo.com/repo/foo.roa",
30-
wantFail: false,
31-
expected: "r.magellan.ipxo.com/repo",
32-
},
3327
}
3428

3529
for _, test := range tests {

0 commit comments

Comments
 (0)