Make sure ipfs add output is sorted by name
License: MIT Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
Christian Couder committed
Dec 20, 2014 at 16:39 UTC
d490a8570648f4d471db227f70d0408c7e84813d
1 file changed
+16
core/commands/add.go
+16
@@ -6,6 +6,7 @@ import (
6
"fmt"
7
"io"
8
"path"
9
+ "sort"
10
11
cmds "github.com/jbenet/go-ipfs/commands"
12
core "github.com/jbenet/go-ipfs/core"
@@ -82,6 +83,8 @@ remains to be implemented.
83
return nil, u.ErrCast()
84
}
85
86
+ sort.Stable(val)
87
+
88
var buf bytes.Buffer
89
for i, obj := range val.Objects {
90
if val.Quiet {
@@ -197,3 +200,16 @@ func addDagnode(output *AddOutput, name string, dn *dag.Node) error {
200
output.Names = append(output.Names, name)
201
return nil
202
}
203
+
204
+// Sort interface implementation to sort add output by name
205
+
206
+func (a AddOutput) Len() int {
207
+ return len(a.Names)
208
+}
209
+func (a AddOutput) Swap(i, j int) {
210
+ a.Names[i], a.Names[j] = a.Names[j], a.Names[i]
211
+ a.Objects[i], a.Objects[j] = a.Objects[j], a.Objects[i]
212
+}
213
+func (a AddOutput) Less(i, j int) bool {
214
+ return a.Names[i] < a.Names[j]
215
+}