diff options
| author | Numblgw <44025291+Numblgw@users.noreply.github.com> | 2024-11-22 00:25:12 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-11-21 08:25:12 -0800 |
| commit | aebf3952b71d44e039c30ff9477f366355ccc523 (patch) | |
| tree | a8c4a09f14be5056726ac5e3bfdbf39bcfa78456 /weed/command/filer_sync.go | |
| parent | 7fa4e5c2a113c96ce3dab5146f9f92b67f3cca36 (diff) | |
| download | seaweedfs-aebf3952b71d44e039c30ff9477f366355ccc523.tar.xz seaweedfs-aebf3952b71d44e039c30ff9477f366355ccc523.zip | |
filer sync: source path and exclude path support dir suffix (#6268)
filer sync: source path and exclude paht support dir suffix
Co-authored-by: liguowei <liguowei@xinye.com>
Diffstat (limited to 'weed/command/filer_sync.go')
| -rw-r--r-- | weed/command/filer_sync.go | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/weed/command/filer_sync.go b/weed/command/filer_sync.go index 8201aa712..9b489297c 100644 --- a/weed/command/filer_sync.go +++ b/weed/command/filer_sync.go @@ -4,6 +4,12 @@ import ( "context" "errors" "fmt" + "os" + "regexp" + "strings" + "sync/atomic" + "time" + "github.com/seaweedfs/seaweedfs/weed/glog" "github.com/seaweedfs/seaweedfs/weed/pb" "github.com/seaweedfs/seaweedfs/weed/pb/filer_pb" @@ -16,11 +22,6 @@ import ( "github.com/seaweedfs/seaweedfs/weed/util" "github.com/seaweedfs/seaweedfs/weed/util/grace" "google.golang.org/grpc" - "os" - "regexp" - "strings" - "sync/atomic" - "time" ) type SyncOptions struct { @@ -403,11 +404,11 @@ func genProcessFunction(sourcePath string, targetPath string, excludePaths []str return nil } - if !strings.HasPrefix(resp.Directory, sourcePath) { + if !strings.HasPrefix(resp.Directory+"/", sourcePath) { return nil } for _, excludePath := range excludePaths { - if strings.HasPrefix(resp.Directory, excludePath) { + if strings.HasPrefix(resp.Directory+"/", excludePath) { return nil } } @@ -454,7 +455,11 @@ func genProcessFunction(sourcePath string, targetPath string, excludePaths []str // new key is also in the watched directory if doDeleteFiles { oldKey := util.Join(targetPath, string(sourceOldKey)[len(sourcePath):]) - message.NewParentPath = util.Join(targetPath, message.NewParentPath[len(sourcePath):]) + if strings.HasSuffix(sourcePath, "/") { + message.NewParentPath = util.Join(targetPath, message.NewParentPath[len(sourcePath)-1:]) + } else { + message.NewParentPath = util.Join(targetPath, message.NewParentPath[len(sourcePath):]) + } foundExisting, err := dataSink.UpdateEntry(string(oldKey), message.OldEntry, message.NewParentPath, message.NewEntry, message.DeleteChunks, message.Signatures) if foundExisting { return err |
