github.com/keybase/client/go@v0.0.0-20240309051027-028f7c731f8b/kbfs/data/dir_entry.go (about) 1 // Copyright 2016 Keybase Inc. All rights reserved. 2 // Use of this source code is governed by a BSD 3 // license that can be found in the LICENSE file. 4 5 package data 6 7 import "github.com/keybase/go-codec/codec" 8 9 // DirEntry is all the data info a directory know about its child. 10 type DirEntry struct { 11 BlockInfo 12 EntryInfo 13 14 codec.UnknownFieldSetHandler 15 } 16 17 // IsInitialized returns true if this DirEntry has been initialized. 18 func (de *DirEntry) IsInitialized() bool { 19 return de.BlockPointer.IsInitialized() 20 } 21 22 // DirEntryWithName combines a DirEntry with the name pointing to that 23 // entry within a directory. 24 type DirEntryWithName struct { 25 DirEntry 26 entryName string 27 } 28 29 // DirEntries is a slice of `DirEntryWithName` instances. 30 type DirEntries []DirEntryWithName 31 32 // DirEntriesBySizeAsc sorts entries in order of ascending name. 33 type DirEntriesBySizeAsc struct{ DirEntries } 34 35 // DirEntriesBySizeDesc sorts entries in order of descending name. 36 type DirEntriesBySizeDesc struct{ DirEntries } 37 38 // Swap implements the sort.Interface interface for DirEntries. 39 func (d DirEntries) Swap(i, j int) { d[i], d[j] = d[j], d[i] } 40 41 // Len implements the sort.Interface interface for DirEntries. 42 func (d DirEntries) Len() int { return len(d) } 43 44 // Less implements the sort.Interface interface for DirEntriesBySizeAsc. 45 func (d DirEntriesBySizeAsc) Less(i, j int) bool { return d.DirEntries[i].Size < d.DirEntries[j].Size } 46 47 // Less implements the sort.Interface interface for DirEntriesBySizeDesc. 48 func (d DirEntriesBySizeDesc) Less(i, j int) bool { return d.DirEntries[i].Size > d.DirEntries[j].Size } 49 50 // DirEntryMapToDirEntries returns a `DirEntries` slice of all the 51 // entries in the given map. 52 func DirEntryMapToDirEntries(entryMap map[string]DirEntry) DirEntries { 53 dirEntries := make(DirEntries, 0, len(entryMap)) 54 for name, entry := range entryMap { 55 dirEntries = append(dirEntries, DirEntryWithName{entry, name}) 56 } 57 return dirEntries 58 }