fork/gdu
git clone https://git.julia.blue/fork/gdu
1eaa266
master
1package analyze 2 3import ( 4"io" 5"iter" 6"sync" 7"sync/atomic" 8"time" 9 10"github.com/dundee/gdu/v5/pkg/fs" 11) 12 13var _ fs.Item = (* SimpleDir )(nil ) 14 15type TopDir struct { 16Name string 17Size atomic.Int64 18Usage atomic.Int64 19ItemCount atomic.Int64 20Flag rune 21m sync.Mutex 22} 23 24func (d * TopDir )AddUsage (size ,usage ,itemCount int64 ) { 25d .Size .Add (size ) 26d .Usage .Add (usage ) 27d .ItemCount .Add (itemCount ) 28} 29 30func (d * TopDir )GetUsage () (size ,usage ,itemCount int64 ) { 31return d .Size .Load (),d .Usage .Load (),d .ItemCount .Load () 32} 33 34func (d * TopDir )SetFlag (flag rune ) { 35d .m .Lock () 36d .Flag = flag 37d .m .Unlock () 38} 39 40type SimpleFile struct { 41Name string 42Symlink string 43Flag rune 44Size int64 45Usage int64 46ItemCount int64 47IsDir bool 48} 49 50type SimpleDir struct { 51SimpleFile 52Files []SimpleFile 53BasePath string 54} 55 56func (d * SimpleDir )GetName ()string { 57return d .Name 58} 59 60func (d * SimpleDir )GetUsage ()int64 { 61return d .Usage 62} 63 64func (d * SimpleDir )GetSize ()int64 { 65return d .Size 66} 67 68func (d * SimpleDir )IsDir ()bool { 69return true 70} 71 72func (d * SimpleDir )GetPath ()string { 73return d .BasePath + pathSep + d .Name 74} 75 76func (d * SimpleDir )GetFlag ()rune {panic ("not implemented" ) } 77func (d * SimpleDir )GetType ()string {panic ("not implemented" ) } 78func (d * SimpleDir )GetMtime () time.Time {panic ("not implemented" ) } 79func (d * SimpleDir )GetItemCount ()int64 {panic ("not implemented" ) } 80func (d * SimpleDir )GetParent () fs.Item {panic ("not implemented" ) } 81func (d * SimpleDir )SetParent (parent fs.Item ) {panic ("not implemented" ) } 82func (d * SimpleDir )GetMultiLinkedInode ()uint64 {panic ("not implemented" ) } 83func (d * SimpleDir )EncodeJSON (io.Writer ,bool , fs.JSONAttributes )error {panic ("not implemented" ) } 84func (d * SimpleDir )GetItemStats (linkedItems fs.HardLinkedItems ,filteringFiles bool ) (itemCount ,size ,usage int64 ) { 85panic ("not implemented" ) 86} 87 88func (d * SimpleDir )UpdateStats (linkedItems fs.HardLinkedItems ) { 89d .updateStats (linkedItems ,false ) 90} 91 92func (d * SimpleDir )UpdateStatsWithFileFiltering (linkedItems fs.HardLinkedItems ) { 93d .updateStats (linkedItems ,true ) 94} 95 96func (d * SimpleDir )updateStats (_ fs.HardLinkedItems ,_ bool ) { 97var totalSize int64 98var totalUsage int64 99var itemCount int64 100for _ ,entry := range d .Files { 101totalSize += entry .Size 102totalUsage += entry .Usage 103itemCount += entry .ItemCount 104 105switch entry .Flag { 106case '!' ,'.' : 107if d .Flag != '!' { 108d .Flag = '.' 109 } 110 } 111 } 112if len (d .Files )== 0 { 113d .ItemCount = 0 114d .Size = EmptyDirSize 115d .Usage = 0 116 }else { 117d .ItemCount = itemCount + 1 118d .Size = totalSize 119d .Usage = totalUsage 120 } 121} 122func (d * SimpleDir )AddFile (fs.Item ) {panic ("not implemented" ) } 123func (d * SimpleDir )GetFiles (sortBy fs.SortBy ,order fs.SortOrder ) iter.Seq [fs.Item ] { 124return func (yield func (fs.Item )bool ) { 125// Make a copy to avoid modifying the original slice 126sorted := make (fs.Files ,0 ,len (d .Files )) 127 128for _ ,file := range d .Files { 129f := & File { 130Name :file .Name , 131Flag :file .Flag , 132Size :file .Size , 133Usage :file .Usage , 134Parent :d , 135Symlink :file .Symlink , 136 } 137 138if file .IsDir { 139sorted = append (sorted ,& Dir { 140File :f , 141ItemCount :file .ItemCount , 142 }) 143 }else { 144sorted = append (sorted ,f ) 145 } 146 } 147 148sortFiles (sorted ,sortBy ,order ) 149 150for _ ,item := range sorted { 151if ! yield (item ) { 152return 153 } 154 } 155 } 156} 157func (d * SimpleDir )GetFilesLocked (fs.SortBy , fs.SortOrder ) iter.Seq [fs.Item ] { 158panic ("not implemented" ) 159} 160func (d * SimpleDir )RemoveFile (fs.Item ) {panic ("not implemented" ) } 161func (d * SimpleDir )RemoveFileByName (name string ) {panic ("not implemented" ) } 162func (d * SimpleDir )RLock ()func () {panic ("not implemented" ) }