提交 d490a857 作者: Christian Couder 提交者: Juan Batiz-Benet

Make sure ipfs add output is sorted by name

License: MIT
Signed-off-by: 's avatarChristian Couder <chriscool@tuxfamily.org>
上级 cd65ec61
...@@ -6,6 +6,7 @@ import ( ...@@ -6,6 +6,7 @@ import (
"fmt" "fmt"
"io" "io"
"path" "path"
"sort"
cmds "github.com/jbenet/go-ipfs/commands" cmds "github.com/jbenet/go-ipfs/commands"
core "github.com/jbenet/go-ipfs/core" core "github.com/jbenet/go-ipfs/core"
...@@ -82,6 +83,8 @@ remains to be implemented. ...@@ -82,6 +83,8 @@ remains to be implemented.
return nil, u.ErrCast() return nil, u.ErrCast()
} }
sort.Stable(val)
var buf bytes.Buffer var buf bytes.Buffer
for i, obj := range val.Objects { for i, obj := range val.Objects {
if val.Quiet { if val.Quiet {
...@@ -197,3 +200,16 @@ func addDagnode(output *AddOutput, name string, dn *dag.Node) error { ...@@ -197,3 +200,16 @@ func addDagnode(output *AddOutput, name string, dn *dag.Node) error {
output.Names = append(output.Names, name) output.Names = append(output.Names, name)
return nil 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]
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论