forked from TrueCloudLab/frostfs-sdk-go
[#47] netmap: Make PlacementPolicy.WriteStringTo() pass nofunlen, cogognit
REP statement is obligatory, thus insert newline before each statement after REP. Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
parent
25e9336d68
commit
31271ad8b1
1 changed files with 8 additions and 39 deletions
|
@ -393,49 +393,28 @@ func (p *PlacementPolicy) AddFilters(fs ...Filter) {
|
|||
// the result into w. Returns w's errors directly.
|
||||
//
|
||||
// See also DecodeString.
|
||||
//
|
||||
// nolint: funlen, gocognit
|
||||
func (p PlacementPolicy) WriteStringTo(w io.StringWriter) (err error) {
|
||||
writtenSmth := false
|
||||
|
||||
writeLnIfNeeded := func() error {
|
||||
if writtenSmth {
|
||||
_, err = w.WriteString("\n")
|
||||
return err
|
||||
}
|
||||
|
||||
writtenSmth = true
|
||||
|
||||
return nil
|
||||
}
|
||||
delim := ""
|
||||
|
||||
for i := range p.replicas {
|
||||
err = writeLnIfNeeded()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
c := p.replicas[i].GetCount()
|
||||
s := p.replicas[i].GetSelector()
|
||||
|
||||
if s != "" {
|
||||
_, err = w.WriteString(fmt.Sprintf("REP %d IN %s", c, s))
|
||||
_, err = w.WriteString(fmt.Sprintf("%sREP %d IN %s", delim, c, s))
|
||||
} else {
|
||||
_, err = w.WriteString(fmt.Sprintf("REP %d", c))
|
||||
_, err = w.WriteString(fmt.Sprintf("%sREP %d", delim, c))
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
delim = "\n"
|
||||
}
|
||||
|
||||
if p.backupFactor > 0 {
|
||||
err = writeLnIfNeeded()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = w.WriteString(fmt.Sprintf("CBF %d", p.backupFactor))
|
||||
_, err = w.WriteString(fmt.Sprintf("\nCBF %d", p.backupFactor))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -444,12 +423,7 @@ func (p PlacementPolicy) WriteStringTo(w io.StringWriter) (err error) {
|
|||
var s string
|
||||
|
||||
for i := range p.selectors {
|
||||
err = writeLnIfNeeded()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = w.WriteString(fmt.Sprintf("SELECT %d", p.selectors[i].GetCount()))
|
||||
_, err = w.WriteString(fmt.Sprintf("\nSELECT %d", p.selectors[i].GetCount()))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -488,12 +462,7 @@ func (p PlacementPolicy) WriteStringTo(w io.StringWriter) (err error) {
|
|||
}
|
||||
|
||||
for i := range p.filters {
|
||||
err = writeLnIfNeeded()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = w.WriteString("FILTER ")
|
||||
_, err = w.WriteString("\nFILTER ")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue