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
This commit is contained in:
Vitaly 2024-01-06 19:47:55 +03:00 committed by Nick Craig-Wood
parent 070cff8a65
commit 4258ad705e
3 changed files with 9 additions and 2 deletions

View File

@ -219,7 +219,8 @@ type listAllFn func(*entity) bool
// Search is a bit fussy about which characters match // Search is a bit fussy about which characters match
// //
// If the name doesn't match this then do an dir list instead // 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 // 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 // If name isn't good then do an unbounded search
name = "" name = ""
} }
OUTER: OUTER:
for numberOfEntities == maxEntitiesPerPage { for numberOfEntities == maxEntitiesPerPage {
pageNumber++ pageNumber++
@ -258,7 +260,6 @@ OUTER:
err = getUnmarshaledResponse(ctx, f, opts, &responseResult) err = getUnmarshaledResponse(ctx, f, opts, &responseResult)
if err != nil { if err != nil {
return false, fmt.Errorf("getting files failed: %w", err) return false, fmt.Errorf("getting files failed: %w", err)
} }
numberOfEntities = len(responseResult.SearchData.Entities) numberOfEntities = len(responseResult.SearchData.Entities)

View File

@ -13,5 +13,7 @@ func TestIntegration(t *testing.T) {
fstests.Run(t, &fstests.Opt{ fstests.Run(t, &fstests.Opt{
RemoteName: "TestLinkbox:", RemoteName: "TestLinkbox:",
NilObject: (*linkbox.Object)(nil), NilObject: (*linkbox.Object)(nil),
// Linkbox doesn't support leading dots for files
SkipLeadingDot: true,
}) })
} }

View File

@ -303,6 +303,7 @@ type Opt struct {
SkipObjectCheckWrap bool // if set skip ObjectCheckWrap SkipObjectCheckWrap bool // if set skip ObjectCheckWrap
SkipDirectoryCheckWrap bool // if set skip DirectoryCheckWrap SkipDirectoryCheckWrap bool // if set skip DirectoryCheckWrap
SkipInvalidUTF8 bool // if set skip invalid UTF-8 checks 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 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" { if opt.SkipInvalidUTF8 && test.name == "invalid UTF-8" {
t.Skip("Skipping " + test.name) t.Skip("Skipping " + test.name)
} }
if opt.SkipLeadingDot && test.name == "leading dot" {
t.Skip("Skipping " + test.name)
}
// turn raw strings into Standard encoding // turn raw strings into Standard encoding
fileName := encoder.Standard.Encode(test.path) fileName := encoder.Standard.Encode(test.path)
dirName := fileName dirName := fileName