mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
refactor
This commit is contained in:
parent
8f7d2d317f
commit
a539d64896
|
@ -52,8 +52,9 @@ func (c *commandRemoteCache) Do(args []string, commandEnv *CommandEnv, writer io
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
localMountedDir, remoteStorageMountedLocation, remoteStorageConf, detectErr := detectMountInfo(commandEnv, writer, *dir)
|
mappings, localMountedDir, remoteStorageMountedLocation, remoteStorageConf, detectErr := detectMountInfo(commandEnv, writer, *dir)
|
||||||
if detectErr != nil{
|
if detectErr != nil{
|
||||||
|
jsonPrintln(writer, mappings)
|
||||||
return detectErr
|
return detectErr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,8 +54,9 @@ func (c *commandRemoteMetaSync) Do(args []string, commandEnv *CommandEnv, writer
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
localMountedDir, remoteStorageMountedLocation, remoteStorageConf, detectErr := detectMountInfo(commandEnv, writer, *dir)
|
mappings, localMountedDir, remoteStorageMountedLocation, remoteStorageConf, detectErr := detectMountInfo(commandEnv, writer, *dir)
|
||||||
if detectErr != nil{
|
if detectErr != nil{
|
||||||
|
jsonPrintln(writer, mappings)
|
||||||
return detectErr
|
return detectErr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,14 +68,13 @@ func (c *commandRemoteMetaSync) Do(args []string, commandEnv *CommandEnv, writer
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func detectMountInfo(commandEnv *CommandEnv, writer io.Writer, dir string) (string, *filer_pb.RemoteStorageLocation, *filer_pb.RemoteConf, error) {
|
func detectMountInfo(commandEnv *CommandEnv, writer io.Writer, dir string) (*filer_pb.RemoteStorageMapping, string, *filer_pb.RemoteStorageLocation, *filer_pb.RemoteConf, error) {
|
||||||
mappings, listErr := filer.ReadMountMappings(commandEnv.option.GrpcDialOption, commandEnv.option.FilerAddress)
|
mappings, listErr := filer.ReadMountMappings(commandEnv.option.GrpcDialOption, commandEnv.option.FilerAddress)
|
||||||
if listErr != nil {
|
if listErr != nil {
|
||||||
return "", nil, nil, listErr
|
return nil, "", nil, nil, listErr
|
||||||
}
|
}
|
||||||
if dir == "" {
|
if dir == "" {
|
||||||
jsonPrintln(writer, mappings)
|
return mappings, "", nil, nil, fmt.Errorf("need to specify '-dir' option")
|
||||||
return "", nil, nil, fmt.Errorf("need to specify '-dir' option")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var localMountedDir string
|
var localMountedDir string
|
||||||
|
@ -85,17 +85,16 @@ func detectMountInfo(commandEnv *CommandEnv, writer io.Writer, dir string) (stri
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if localMountedDir == "" {
|
if localMountedDir == "" {
|
||||||
jsonPrintln(writer, mappings)
|
return mappings, localMountedDir, remoteStorageMountedLocation, nil, fmt.Errorf("%s is not mounted", dir)
|
||||||
return "", nil, nil, fmt.Errorf("%s is not mounted", dir)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// find remote storage configuration
|
// find remote storage configuration
|
||||||
remoteStorageConf, err := filer.ReadRemoteStorageConf(commandEnv.option.GrpcDialOption, commandEnv.option.FilerAddress, remoteStorageMountedLocation.Name)
|
remoteStorageConf, err := filer.ReadRemoteStorageConf(commandEnv.option.GrpcDialOption, commandEnv.option.FilerAddress, remoteStorageMountedLocation.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", nil, nil, err
|
return mappings, localMountedDir, remoteStorageMountedLocation, remoteStorageConf, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return localMountedDir, remoteStorageMountedLocation, remoteStorageConf, nil
|
return mappings, localMountedDir, remoteStorageMountedLocation, remoteStorageConf, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -95,6 +95,9 @@ func listExistingRemoteStorageMounts(commandEnv *CommandEnv, writer io.Writer) (
|
||||||
}
|
}
|
||||||
|
|
||||||
func jsonPrintln(writer io.Writer, message proto.Message) error {
|
func jsonPrintln(writer io.Writer, message proto.Message) error {
|
||||||
|
if message == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
m := jsonpb.Marshaler{
|
m := jsonpb.Marshaler{
|
||||||
EmitDefaults: false,
|
EmitDefaults: false,
|
||||||
Indent: " ",
|
Indent: " ",
|
||||||
|
|
Loading…
Reference in a new issue