gitlab.com/evatix-go/core@v1.3.55/chmodhelper/RwxMatchingStatus.go (about) 1 package chmodhelper 2 3 import ( 4 "strings" 5 6 "gitlab.com/evatix-go/core/constants" 7 "gitlab.com/evatix-go/core/errcore" 8 ) 9 10 type RwxMatchingStatus struct { 11 RwxMismatchInfos []*RwxMismatchInfo 12 MissingOrPathsWithIssues []string 13 IsAllMatching bool 14 Error error 15 } 16 17 func InvalidRwxMatchingStatus(err error) *RwxMatchingStatus { 18 return &RwxMatchingStatus{ 19 RwxMismatchInfos: []*RwxMismatchInfo{}, 20 MissingOrPathsWithIssues: []string{}, 21 IsAllMatching: false, 22 Error: err, 23 } 24 } 25 26 func EmptyRwxMatchingStatus() *RwxMatchingStatus { 27 return &RwxMatchingStatus{ 28 RwxMismatchInfos: []*RwxMismatchInfo{}, 29 MissingOrPathsWithIssues: []string{}, 30 IsAllMatching: false, 31 Error: nil, 32 } 33 } 34 35 func (it *RwxMatchingStatus) MissingFilesToString() string { 36 return strings.Join(it.MissingOrPathsWithIssues, constants.CommaSpace) 37 } 38 39 func (it *RwxMatchingStatus) CreateErrFinalError() error { 40 if it.IsAllMatching && it.Error == nil { 41 return nil 42 } 43 44 length := len(it.RwxMismatchInfos) + 45 constants.Capacity2 46 47 sliceErr := make([]string, 0, length) 48 49 for _, info := range it.RwxMismatchInfos { 50 expectingMessage := errcore.ExpectingSimpleNoType( 51 info.FilePath, 52 info.Expecting, 53 info.Actual) 54 55 sliceErr = append( 56 sliceErr, 57 expectingMessage) 58 } 59 60 if it.Error != nil { 61 sliceErr = append( 62 sliceErr, 63 it.Error.Error()) 64 } 65 66 return errcore.SliceToError(sliceErr) 67 }