diff options
| author | Chris Lu <chris.lu@gmail.com> | 2021-08-15 01:53:46 -0700 |
|---|---|---|
| committer | Chris Lu <chris.lu@gmail.com> | 2021-08-15 01:53:46 -0700 |
| commit | 9462f5129a8c6c66200150b41ddfe96a3dd0454e (patch) | |
| tree | 76c1782fe91d0d6adcb63a6435d217d48fd85f78 /weed/shell/command_remote_mount.go | |
| parent | 3ada61c875158dedd24618013da01939cc7acc07 (diff) | |
| download | seaweedfs-9462f5129a8c6c66200150b41ddfe96a3dd0454e.tar.xz seaweedfs-9462f5129a8c6c66200150b41ddfe96a3dd0454e.zip | |
shell: add "remote.meta.sync"
Diffstat (limited to 'weed/shell/command_remote_mount.go')
| -rw-r--r-- | weed/shell/command_remote_mount.go | 61 |
1 files changed, 6 insertions, 55 deletions
diff --git a/weed/shell/command_remote_mount.go b/weed/shell/command_remote_mount.go index 2483fa5be..077c64e94 100644 --- a/weed/shell/command_remote_mount.go +++ b/weed/shell/command_remote_mount.go @@ -67,8 +67,8 @@ func (c *commandRemoteMount) Do(args []string, commandEnv *CommandEnv, writer io return fmt.Errorf("find configuration for %s: %v", *remote, err) } - // pull metadata from remote - if err = c.pullMetadata(commandEnv, writer, *dir, *nonEmpty, remoteConf, remoteStorageLocation); err != nil { + // sync metadata from remote + if err = c.syncMetadata(commandEnv, writer, *dir, *nonEmpty, remoteConf, remoteStorageLocation); err != nil { return fmt.Errorf("pull metadata: %v", err) } @@ -111,7 +111,7 @@ func (c *commandRemoteMount) findRemoteStorageConfiguration(commandEnv *CommandE } -func (c *commandRemoteMount) pullMetadata(commandEnv *CommandEnv, writer io.Writer, dir string, nonEmpty bool, remoteConf *filer_pb.RemoteConf, remote *filer_pb.RemoteStorageLocation) error { +func (c *commandRemoteMount) syncMetadata(commandEnv *CommandEnv, writer io.Writer, dir string, nonEmpty bool, remoteConf *filer_pb.RemoteConf, remote *filer_pb.RemoteStorageLocation) error { // find existing directory, and ensure the directory is empty err := commandEnv.WithFilerClient(func(client filer_pb.SeaweedFilerClient) error { @@ -146,58 +146,9 @@ func (c *commandRemoteMount) pullMetadata(commandEnv *CommandEnv, writer io.Writ return err } - // visit remote storage - remoteStorage, err := remote_storage.GetRemoteStorage(remoteConf) - if err != nil { - return err - } - - err = commandEnv.WithFilerClient(func(client filer_pb.SeaweedFilerClient) error { - ctx := context.Background() - err = remoteStorage.Traverse(remote, func(remoteDir, name string, isDirectory bool, remoteEntry *filer_pb.RemoteEntry) error { - localDir := dir + remoteDir - println(util.NewFullPath(localDir, name)) - - lookupResponse, lookupErr := filer_pb.LookupEntry(client, &filer_pb.LookupDirectoryEntryRequest{ - Directory: localDir, - Name: name, - }) - var existingEntry *filer_pb.Entry - if lookupErr != nil { - if lookupErr != filer_pb.ErrNotFound { - return lookupErr - } - } else { - existingEntry = lookupResponse.Entry - } - - if existingEntry == nil { - _, createErr := client.CreateEntry(ctx, &filer_pb.CreateEntryRequest{ - Directory: localDir, - Entry: &filer_pb.Entry{ - Name: name, - IsDirectory: isDirectory, - Attributes: &filer_pb.FuseAttributes{ - FileSize: uint64(remoteEntry.RemoteSize), - Mtime: remoteEntry.RemoteMtime, - FileMode: uint32(0644), - }, - RemoteEntry: remoteEntry, - }, - }) - return createErr - } else { - if existingEntry.RemoteEntry == nil || existingEntry.RemoteEntry.RemoteETag != remoteEntry.RemoteETag { - return doSaveRemoteEntry(client, localDir, existingEntry, remoteEntry) - } - } - return nil - }) - return err - }) - - if err != nil { - return err + // pull metadata from remote + if err = pullMetadata(commandEnv, writer, util.FullPath(dir), remote, util.FullPath(dir), remoteConf); err != nil { + return fmt.Errorf("cache content data: %v", err) } return nil |
