2016-08-31 19:18:51 +02:00
|
|
|
package restic
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/hex"
|
2022-12-03 11:55:33 +01:00
|
|
|
"strings"
|
2016-08-31 19:18:51 +02:00
|
|
|
)
|
|
|
|
|
2022-12-03 11:55:33 +01:00
|
|
|
// IDs is a slice of IDs that implements sort.Interface and fmt.Stringer.
|
2016-08-31 19:18:51 +02:00
|
|
|
type IDs []ID
|
|
|
|
|
|
|
|
func (ids IDs) Len() int {
|
|
|
|
return len(ids)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ids IDs) Less(i, j int) bool {
|
2022-12-03 11:55:33 +01:00
|
|
|
return string(ids[i][:]) < string(ids[j][:])
|
2016-08-31 19:18:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (ids IDs) Swap(i, j int) {
|
|
|
|
ids[i], ids[j] = ids[j], ids[i]
|
|
|
|
}
|
|
|
|
|
2022-12-03 11:55:33 +01:00
|
|
|
func (ids IDs) String() string {
|
|
|
|
var sb strings.Builder
|
|
|
|
sb.Grow(1 + (1+2*shortStr)*len(ids))
|
|
|
|
|
|
|
|
buf := make([]byte, 2*shortStr)
|
2016-08-31 19:18:51 +02:00
|
|
|
|
2022-12-03 11:55:33 +01:00
|
|
|
sb.WriteByte('[')
|
|
|
|
for i, id := range ids {
|
|
|
|
if i > 0 {
|
|
|
|
sb.WriteByte(' ')
|
2016-08-31 19:18:51 +02:00
|
|
|
}
|
2022-12-03 11:55:33 +01:00
|
|
|
hex.Encode(buf, id[:shortStr])
|
|
|
|
sb.Write(buf)
|
2016-08-31 19:18:51 +02:00
|
|
|
}
|
2022-12-03 11:55:33 +01:00
|
|
|
sb.WriteByte(']')
|
2016-08-31 19:18:51 +02:00
|
|
|
|
2022-12-03 11:55:33 +01:00
|
|
|
return sb.String()
|
2016-08-31 19:18:51 +02:00
|
|
|
}
|