From 339d3e8ee63decb35265b54ba3ba0943e64bb349 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Thu, 7 Mar 2024 12:35:26 +0000 Subject: [PATCH] netstorage,quatrix,seafile: fix Root to return correct directory when pointing to a file This fixes the TestIntegration/FsMkdir/FsPutFiles/FsIsFile/FsRoot integration test. --- backend/netstorage/netstorage.go | 6 ++++++ backend/quatrix/quatrix.go | 5 +++++ backend/seafile/seafile.go | 5 +++++ 3 files changed, 16 insertions(+) diff --git a/backend/netstorage/netstorage.go b/backend/netstorage/netstorage.go index d5a0e9c6b..d365918ca 100755 --- a/backend/netstorage/netstorage.go +++ b/backend/netstorage/netstorage.go @@ -15,6 +15,7 @@ import ( "math/rand" "net/http" "net/url" + "path" "strconv" "strings" "sync" @@ -260,6 +261,11 @@ func NewFs(ctx context.Context, name, root string, m configmap.Mapper) (fs.Fs, e case fs.ErrorObjectNotFound: return f, nil case fs.ErrorIsFile: + // Correct root if definitely pointing to a file + f.root = path.Dir(f.root) + if f.root == "." || f.root == "/" { + f.root = "" + } // Fs points to the parent directory return f, err default: diff --git a/backend/quatrix/quatrix.go b/backend/quatrix/quatrix.go index 91d8c69d9..ba15225b3 100644 --- a/backend/quatrix/quatrix.go +++ b/backend/quatrix/quatrix.go @@ -235,6 +235,11 @@ func NewFs(ctx context.Context, name, root string, m configmap.Mapper) (fs.Fs, e if fileID.IsFile() { root, _ = dircache.SplitPath(root) f.dirCache = dircache.New(root, rootID.FileID, f) + // Correct root if definitely pointing to a file + f.root = path.Dir(f.root) + if f.root == "." || f.root == "/" { + f.root = "" + } return f, fs.ErrorIsFile } diff --git a/backend/seafile/seafile.go b/backend/seafile/seafile.go index 3fa3e317a..b38dfa2b5 100644 --- a/backend/seafile/seafile.go +++ b/backend/seafile/seafile.go @@ -301,6 +301,11 @@ func NewFs(ctx context.Context, name, root string, m configmap.Mapper) (fs.Fs, e } return f, err } + // Correct root if definitely pointing to a file + f.root = path.Dir(f.root) + if f.root == "." || f.root == "/" { + f.root = "" + } // return an error with an fs which points to the parent return f, fs.ErrorIsFile }