Browse Source

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>
pull/6288/head
Numblgw 1 month ago
committed by GitHub
parent
commit
aebf3952b7
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 19
      weed/command/filer_sync.go

19
weed/command/filer_sync.go

@ -4,6 +4,12 @@ import (
"context" "context"
"errors" "errors"
"fmt" "fmt"
"os"
"regexp"
"strings"
"sync/atomic"
"time"
"github.com/seaweedfs/seaweedfs/weed/glog" "github.com/seaweedfs/seaweedfs/weed/glog"
"github.com/seaweedfs/seaweedfs/weed/pb" "github.com/seaweedfs/seaweedfs/weed/pb"
"github.com/seaweedfs/seaweedfs/weed/pb/filer_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"
"github.com/seaweedfs/seaweedfs/weed/util/grace" "github.com/seaweedfs/seaweedfs/weed/util/grace"
"google.golang.org/grpc" "google.golang.org/grpc"
"os"
"regexp"
"strings"
"sync/atomic"
"time"
) )
type SyncOptions struct { type SyncOptions struct {
@ -403,11 +404,11 @@ func genProcessFunction(sourcePath string, targetPath string, excludePaths []str
return nil return nil
} }
if !strings.HasPrefix(resp.Directory, sourcePath) {
if !strings.HasPrefix(resp.Directory+"/", sourcePath) {
return nil return nil
} }
for _, excludePath := range excludePaths { for _, excludePath := range excludePaths {
if strings.HasPrefix(resp.Directory, excludePath) {
if strings.HasPrefix(resp.Directory+"/", excludePath) {
return nil return nil
} }
} }
@ -454,7 +455,11 @@ func genProcessFunction(sourcePath string, targetPath string, excludePaths []str
// new key is also in the watched directory // new key is also in the watched directory
if doDeleteFiles { if doDeleteFiles {
oldKey := util.Join(targetPath, string(sourceOldKey)[len(sourcePath):]) oldKey := util.Join(targetPath, string(sourceOldKey)[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):]) 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) foundExisting, err := dataSink.UpdateEntry(string(oldKey), message.OldEntry, message.NewParentPath, message.NewEntry, message.DeleteChunks, message.Signatures)
if foundExisting { if foundExisting {
return err return err

Loading…
Cancel
Save