mirror of
https://github.com/ipfs/kubo.git
synced 2026-03-03 23:38:07 +08:00
Make sure ipfs add output is sorted by name
License: MIT Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
This commit is contained in:
parent
cd65ec614b
commit
d490a85706
@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"path"
|
||||
"sort"
|
||||
|
||||
cmds "github.com/jbenet/go-ipfs/commands"
|
||||
core "github.com/jbenet/go-ipfs/core"
|
||||
@ -82,6 +83,8 @@ remains to be implemented.
|
||||
return nil, u.ErrCast()
|
||||
}
|
||||
|
||||
sort.Stable(val)
|
||||
|
||||
var buf bytes.Buffer
|
||||
for i, obj := range val.Objects {
|
||||
if val.Quiet {
|
||||
@ -197,3 +200,16 @@ func addDagnode(output *AddOutput, name string, dn *dag.Node) error {
|
||||
output.Names = append(output.Names, name)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Sort interface implementation to sort add output by name
|
||||
|
||||
func (a AddOutput) Len() int {
|
||||
return len(a.Names)
|
||||
}
|
||||
func (a AddOutput) Swap(i, j int) {
|
||||
a.Names[i], a.Names[j] = a.Names[j], a.Names[i]
|
||||
a.Objects[i], a.Objects[j] = a.Objects[j], a.Objects[i]
|
||||
}
|
||||
func (a AddOutput) Less(i, j int) bool {
|
||||
return a.Names[i] < a.Names[j]
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user