mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
refactor
This commit is contained in:
parent
72eec84167
commit
35f70c51b0
|
@ -62,20 +62,11 @@ func (c *commandFsConfigure) Do(args []string, commandEnv *CommandEnv, writer io
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var buf bytes.Buffer
|
fc, err := readFilerConf(commandEnv)
|
||||||
if err = commandEnv.WithFilerClient(func(client filer_pb.SeaweedFilerClient) error {
|
if err != nil {
|
||||||
return filer.ReadEntry(commandEnv.MasterClient, client, filer.DirectoryEtcSeaweedFS, filer.FilerConfName, &buf)
|
|
||||||
}); err != nil && err != filer_pb.ErrNotFound {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
fc := filer.NewFilerConf()
|
|
||||||
if buf.Len() > 0 {
|
|
||||||
if err = fc.LoadFromBytes(buf.Bytes()); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if *locationPrefix != "" {
|
if *locationPrefix != "" {
|
||||||
locConf := &filer_pb.FilerConf_PathConf{
|
locConf := &filer_pb.FilerConf_PathConf{
|
||||||
LocationPrefix: *locationPrefix,
|
LocationPrefix: *locationPrefix,
|
||||||
|
@ -112,16 +103,16 @@ func (c *commandFsConfigure) Do(args []string, commandEnv *CommandEnv, writer io
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
buf.Reset()
|
var buf2 bytes.Buffer
|
||||||
fc.ToText(&buf)
|
fc.ToText(&buf2)
|
||||||
|
|
||||||
fmt.Fprintf(writer, string(buf.Bytes()))
|
fmt.Fprintf(writer, string(buf2.Bytes()))
|
||||||
fmt.Fprintln(writer)
|
fmt.Fprintln(writer)
|
||||||
|
|
||||||
if *apply {
|
if *apply {
|
||||||
|
|
||||||
if err = commandEnv.WithFilerClient(func(client filer_pb.SeaweedFilerClient) error {
|
if err = commandEnv.WithFilerClient(func(client filer_pb.SeaweedFilerClient) error {
|
||||||
return filer.SaveInsideFiler(client, filer.DirectoryEtcSeaweedFS, filer.FilerConfName, buf.Bytes())
|
return filer.SaveInsideFiler(client, filer.DirectoryEtcSeaweedFS, filer.FilerConfName, buf2.Bytes())
|
||||||
}); err != nil && err != filer_pb.ErrNotFound {
|
}); err != nil && err != filer_pb.ErrNotFound {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -131,3 +122,20 @@ func (c *commandFsConfigure) Do(args []string, commandEnv *CommandEnv, writer io
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func readFilerConf(commandEnv *CommandEnv) (*filer.FilerConf, error) {
|
||||||
|
var buf bytes.Buffer
|
||||||
|
if err := commandEnv.WithFilerClient(func(client filer_pb.SeaweedFilerClient) error {
|
||||||
|
return filer.ReadEntry(commandEnv.MasterClient, client, filer.DirectoryEtcSeaweedFS, filer.FilerConfName, &buf)
|
||||||
|
}); err != nil && err != filer_pb.ErrNotFound {
|
||||||
|
return nil, fmt.Errorf("read %s/%s: %v", filer.DirectoryEtcSeaweedFS, filer.FilerConfName, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
fc := filer.NewFilerConf()
|
||||||
|
if buf.Len() > 0 {
|
||||||
|
if err := fc.LoadFromBytes(buf.Bytes()); err != nil {
|
||||||
|
return nil, fmt.Errorf("parse %s/%s: %v", filer.DirectoryEtcSeaweedFS, filer.FilerConfName, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return fc, nil
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue