From 4258ad705e344afc13f9b28abca0d03d5ac2963c Mon Sep 17 00:00:00 2001 From: Vitaly <9034218+gvitali@users.noreply.github.com> Date: Sat, 6 Jan 2024 19:47:55 +0300 Subject: [PATCH] linkbox: fix working with names longer than 8-25 Unicode chars. The LinkBox API does not allow searching by more than 25 Unicode characters in the name, for this reason it is currently impossible to work with files and folders named longer than 8 Unicode chars (if encoded in base32). This fix queries all files in a directory for long names and checks their names one by one, thus solving the issue. Fixes #7542 --- backend/linkbox/linkbox.go | 5 +++-- backend/linkbox/linkbox_test.go | 2 ++ fstest/fstests/fstests.go | 4 ++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/backend/linkbox/linkbox.go b/backend/linkbox/linkbox.go index 75445ea72..fd70c2cd5 100644 --- a/backend/linkbox/linkbox.go +++ b/backend/linkbox/linkbox.go @@ -219,7 +219,8 @@ type listAllFn func(*entity) bool // Search is a bit fussy about which characters match // // If the name doesn't match this then do an dir list instead -var searchOK = regexp.MustCompile(`^[a-zA-Z0-9_ .]+$`) +// N.B.: Linkbox doesn't support search by name that is longer than 50 chars +var searchOK = regexp.MustCompile(`^[a-zA-Z0-9_ .]{1,50}$`) // Lists the directory required calling the user function on each item found // @@ -238,6 +239,7 @@ func (f *Fs) listAll(ctx context.Context, dirID string, name string, fn listAllF // If name isn't good then do an unbounded search name = "" } + OUTER: for numberOfEntities == maxEntitiesPerPage { pageNumber++ @@ -258,7 +260,6 @@ OUTER: err = getUnmarshaledResponse(ctx, f, opts, &responseResult) if err != nil { return false, fmt.Errorf("getting files failed: %w", err) - } numberOfEntities = len(responseResult.SearchData.Entities) diff --git a/backend/linkbox/linkbox_test.go b/backend/linkbox/linkbox_test.go index aa03c79ca..d9b448c0c 100644 --- a/backend/linkbox/linkbox_test.go +++ b/backend/linkbox/linkbox_test.go @@ -13,5 +13,7 @@ func TestIntegration(t *testing.T) { fstests.Run(t, &fstests.Opt{ RemoteName: "TestLinkbox:", NilObject: (*linkbox.Object)(nil), + // Linkbox doesn't support leading dots for files + SkipLeadingDot: true, }) } diff --git a/fstest/fstests/fstests.go b/fstest/fstests/fstests.go index 58420991f..3e3237f1a 100644 --- a/fstest/fstests/fstests.go +++ b/fstest/fstests/fstests.go @@ -303,6 +303,7 @@ type Opt struct { SkipObjectCheckWrap bool // if set skip ObjectCheckWrap SkipDirectoryCheckWrap bool // if set skip DirectoryCheckWrap SkipInvalidUTF8 bool // if set skip invalid UTF-8 checks + SkipLeadingDot bool // if set skip leading dot checks QuickTestOK bool // if set, run this test with make quicktest } @@ -690,6 +691,9 @@ func Run(t *testing.T, opt *Opt) { if opt.SkipInvalidUTF8 && test.name == "invalid UTF-8" { t.Skip("Skipping " + test.name) } + if opt.SkipLeadingDot && test.name == "leading dot" { + t.Skip("Skipping " + test.name) + } // turn raw strings into Standard encoding fileName := encoder.Standard.Encode(test.path) dirName := fileName