2021-12-09 19:08:05 +00:00
|
|
|
// Copyright (C) 2021 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package ulfs
|
|
|
|
|
2022-01-06 19:55:46 +00:00
|
|
|
import "storj.io/storj/cmd/uplink/ulloc"
|
2021-12-09 19:08:05 +00:00
|
|
|
|
|
|
|
// filteredObjectIterator removes any iteration entries that do not begin with the filter.
|
|
|
|
// all entries must begin with the trim string which is removed before checking for the
|
|
|
|
// filter.
|
|
|
|
type filteredObjectIterator struct {
|
|
|
|
trim ulloc.Location
|
|
|
|
filter ulloc.Location
|
|
|
|
iter ObjectIterator
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *filteredObjectIterator) Next() bool {
|
|
|
|
for {
|
|
|
|
if !f.iter.Next() {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
loc := f.iter.Item().Loc
|
|
|
|
if !loc.HasPrefix(f.trim) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if loc.HasPrefix(f.filter.AsDirectoryish()) || loc == f.filter {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *filteredObjectIterator) Err() error { return f.iter.Err() }
|
|
|
|
|
|
|
|
func (f *filteredObjectIterator) Item() ObjectInfo {
|
|
|
|
item := f.iter.Item()
|
|
|
|
item.Loc = item.Loc.RemovePrefix(f.trim)
|
|
|
|
return item
|
|
|
|
}
|
|
|
|
|
|
|
|
// emptyObjectIterator is an objectIterator that has no objects.
|
|
|
|
type emptyObjectIterator struct{}
|
|
|
|
|
|
|
|
func (emptyObjectIterator) Next() bool { return false }
|
|
|
|
func (emptyObjectIterator) Err() error { return nil }
|
|
|
|
func (emptyObjectIterator) Item() ObjectInfo { return ObjectInfo{} }
|