gitlab.com/evatix-go/core@v1.3.55/chmodhelper/FilteredPathFileInfoMap.go (about) 1 package chmodhelper 2 3 import ( 4 "os" 5 "strings" 6 7 "gitlab.com/evatix-go/core/constants" 8 ) 9 10 type FilteredPathFileInfoMap struct { 11 lazyValidLocations []string 12 lazyValidLocationFileInfoRwxWrappers []LocationFileInfoRwxWrapper 13 FilesToInfoMap map[string]os.FileInfo 14 PathsRemainsUnProcessed []string // TODO 15 MissingOrOtherPathIssues []string 16 Error error 17 } 18 19 func (it *FilteredPathFileInfoMap) LazyValidLocationFileInfoRwxWrappers() []LocationFileInfoRwxWrapper { 20 if it.lazyValidLocationFileInfoRwxWrappers != nil { 21 return it.lazyValidLocationFileInfoRwxWrappers 22 } 23 24 it.lazyValidLocationFileInfoRwxWrappers = 25 it.ValidLocationFileInfoRwxWrappers() 26 27 return it.lazyValidLocationFileInfoRwxWrappers 28 } 29 30 func (it *FilteredPathFileInfoMap) LazyValidLocations() []string { 31 if it.lazyValidLocations != nil { 32 return it.lazyValidLocations 33 } 34 35 it.lazyValidLocations = it.ValidLocations() 36 37 return it.lazyValidLocations 38 } 39 40 func (it *FilteredPathFileInfoMap) ValidLocations() []string { 41 length := len(it.FilesToInfoMap) 42 slice := make([]string, length) 43 44 if length == 0 { 45 return slice 46 } 47 48 index := 0 49 for s := range it.FilesToInfoMap { 50 slice[index] = s 51 index++ 52 } 53 54 return slice 55 } 56 57 func (it *FilteredPathFileInfoMap) ValidFileInfos() []os.FileInfo { 58 length := len(it.FilesToInfoMap) 59 slice := make([]os.FileInfo, length) 60 61 if length == 0 { 62 return slice 63 } 64 65 index := 0 66 for _, fileInfo := range it.FilesToInfoMap { 67 slice[index] = fileInfo 68 index++ 69 } 70 71 return slice 72 } 73 74 func (it *FilteredPathFileInfoMap) ValidLocationFileInfoRwxWrappers() []LocationFileInfoRwxWrapper { 75 length := len(it.FilesToInfoMap) 76 slice := make([]LocationFileInfoRwxWrapper, length) 77 78 if length == 0 { 79 return slice 80 } 81 82 index := 0 83 for location, fileInfo := range it.FilesToInfoMap { 84 slice[index] = LocationFileInfoRwxWrapper{ 85 Location: location, 86 FileInfo: fileInfo, 87 RwxWrapper: New.RwxWrapper.UsingFileModePtr(fileInfo.Mode()), 88 } 89 90 index++ 91 } 92 93 return slice 94 } 95 96 func InvalidFilteredPathFileInfoMap() *FilteredPathFileInfoMap { 97 return &FilteredPathFileInfoMap{ 98 FilesToInfoMap: map[string]os.FileInfo{}, 99 MissingOrOtherPathIssues: []string{}, 100 Error: nil, 101 } 102 } 103 104 func (it *FilteredPathFileInfoMap) HasAnyValidFileInfo() bool { 105 return len(it.FilesToInfoMap) > 0 106 } 107 108 func (it *FilteredPathFileInfoMap) IsEmptyValidFileInfos() bool { 109 return len(it.FilesToInfoMap) == 0 110 } 111 112 func (it *FilteredPathFileInfoMap) LengthOfIssues() int { 113 return len(it.MissingOrOtherPathIssues) 114 } 115 116 func (it *FilteredPathFileInfoMap) IsEmptyIssues() bool { 117 return len(it.MissingOrOtherPathIssues) == 0 118 } 119 120 func (it *FilteredPathFileInfoMap) HasAnyIssues() bool { 121 return it.Error != nil || it.HasAnyMissingPaths() 122 } 123 124 func (it *FilteredPathFileInfoMap) HasError() bool { 125 return it.Error != nil 126 } 127 128 func (it *FilteredPathFileInfoMap) HasAnyMissingPaths() bool { 129 return len(it.MissingOrOtherPathIssues) > 0 130 } 131 132 func (it *FilteredPathFileInfoMap) MissingPathsToString() string { 133 return strings.Join(it.MissingOrOtherPathIssues, constants.CommaSpace) 134 }