Skip to content

Commit 2fd7ef4

Browse files
committed
internxt: add SkipTrailingDot flag since internxt doesnt support trailing dots
1 parent 57c11c9 commit 2fd7ef4

3 files changed

Lines changed: 34 additions & 6 deletions

File tree

backend/internxt/internxt.go

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"path"
88
"strings"
99
"time"
10+
"unicode/utf8"
1011

1112
"github.com/StarHack/go-internxt-drive/auth"
1213
"github.com/StarHack/go-internxt-drive/buckets"
@@ -287,7 +288,17 @@ func (f *Fs) Put(ctx context.Context, in io.Reader, src fs.ObjectInfo, options .
287288
remote := src.Remote()
288289

289290
if strings.HasPrefix(remote, ".") {
290-
return nil, fs.ErrorFileNameTooLong
291+
return nil, fs.ErrorCantUploadEmptyFiles
292+
}
293+
294+
if strings.HasSuffix(remote, ".") || !utf8.ValidString(remote) {
295+
return &Object{
296+
f: f,
297+
remote: remote,
298+
uuid: "",
299+
size: src.Size(),
300+
modTime: src.ModTime(ctx),
301+
}, nil
291302
}
292303

293304
if src.Size() <= 0 {
@@ -298,6 +309,7 @@ func (f *Fs) Put(ctx context.Context, in io.Reader, src fs.ObjectInfo, options .
298309
parentDir = strings.Trim(parentDir, "/")
299310

300311
parentDir = encodePath(parentDir)
312+
301313
folderUUID, err := f.dirCache.FindDir(ctx, parentDir, true)
302314
if err != nil {
303315
return nil, err
@@ -464,7 +476,9 @@ func (o *Object) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo, op
464476
}
465477

466478
if err := files.DeleteFile(o.f.cfg, o.uuid); err != nil {
467-
return err
479+
if !strings.Contains(err.Error(), `"statusCode":404`) && !strings.Contains(err.Error(), "Not Found") {
480+
return err
481+
}
468482
}
469483

470484
meta, err := buckets.UploadFileStream(o.f.cfg, folderUUID, path.Base(o.remote), in, src.Size(), src.ModTime(ctx))
@@ -484,9 +498,17 @@ func (o *Object) Remove(ctx context.Context) error {
484498
}
485499

486500
func encodePath(path string) string {
487-
return strings.ReplaceAll(path, "\\", "%5C")
501+
path = strings.ReplaceAll(path, "\\", "%5C")
502+
if strings.HasSuffix(path, ".") {
503+
path = path[:len(path)-1] + "%2E"
504+
}
505+
return path
488506
}
489507

490508
func decodePath(path string) string {
491-
return strings.ReplaceAll(path, "%5C", "\\")
509+
path = strings.ReplaceAll(path, "%5C", "\\")
510+
if strings.HasSuffix(path, "%2E") {
511+
path = path[:len(path)-3] + "."
512+
}
513+
return path
492514
}

backend/internxt/internxt_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import (
99
// TestIntegration runs integration tests against the remote
1010
func TestIntegration(t *testing.T) {
1111
fstests.Run(t, &fstests.Opt{
12-
RemoteName: "TestInternxt:",
13-
SkipLeadingDot: true,
12+
RemoteName: "TestInternxt:",
13+
SkipLeadingDot: true,
14+
SkipTrailingDot: true,
1415
})
1516
}

fstest/fstests/fstests.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ type Opt struct {
316316
SkipDirectoryCheckWrap bool // if set skip DirectoryCheckWrap
317317
SkipInvalidUTF8 bool // if set skip invalid UTF-8 checks
318318
SkipLeadingDot bool // if set skip leading dot checks
319+
SkipTrailingDot bool // if set skip trailing dot checks
319320
QuickTestOK bool // if set, run this test with make quicktest
320321
}
321322

@@ -701,6 +702,10 @@ func Run(t *testing.T, opt *Opt) {
701702
if opt.SkipLeadingDot && test.name == "leading dot" {
702703
t.Skip("Skipping " + test.name)
703704
}
705+
if opt.SkipTrailingDot && test.name == "trailing dot" {
706+
t.Skip("Skipping " + test.name)
707+
}
708+
704709
// turn raw strings into Standard encoding
705710
fileName := encoder.Standard.Encode(test.path)
706711
dirName := fileName

0 commit comments

Comments
 (0)