Skip to content

Commit 8940418

Browse files
committed
value: support duplicates
e.g. `adb pull DEVICE_FILE {DEVICE_FILE | LOCAL_FILE}...`
1 parent 043c1f3 commit 8940418

2 files changed

Lines changed: 21 additions & 5 deletions

File tree

internal/common/value.go

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,13 @@ func RawValuesFrom(values ...string) RawValues {
4747
}
4848

4949
func (r RawValues) Unique() RawValues {
50-
uniqueRawValues := make(map[string]RawValue)
50+
type key struct {
51+
Value string
52+
Uid string
53+
}
54+
uniqueRawValues := make(map[key]RawValue)
5155
for _, value := range r {
52-
uniqueRawValues[value.Value] = value
56+
uniqueRawValues[key{value.Value, value.Uid}] = value
5357
}
5458

5559
rawValues := make([]RawValue, 0, len(uniqueRawValues))
@@ -150,6 +154,17 @@ func (a ByValue) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
150154
// ByDisplay alias to filter by display.
151155
type ByDisplay []RawValue
152156

153-
func (a ByDisplay) Len() int { return len(a) }
154-
func (a ByDisplay) Less(i, j int) bool { return a[i].Display < a[j].Display }
155-
func (a ByDisplay) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
157+
func (a ByDisplay) Len() int { return len(a) }
158+
func (a ByDisplay) Less(i, j int) bool {
159+
if a[i].Display == a[j].Display {
160+
return ByUid(a).Less(i, j) // ensure consistency in export
161+
}
162+
return a[i].Display < a[j].Display
163+
}
164+
func (a ByDisplay) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
165+
166+
type ByUid []RawValue
167+
168+
func (a ByUid) Len() int { return len(a) }
169+
func (a ByUid) Less(i, j int) bool { return a[i].Uid < a[j].Uid }
170+
func (a ByUid) Swap(i, j int) { a[i], a[j] = a[j], a[i] }

internal/shell/shell.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ func Value(shell string, value string, meta common.Meta, values common.RawValues
117117
for index := range values {
118118
values[index].Uid = ""
119119
}
120+
values = values.Unique() // re-filter after clearance
120121
return f(value, meta, values)
121122
}
122123
return ""

0 commit comments

Comments
 (0)