gitlab.com/evatix-go/core@v1.3.55/chmodhelper/VarAttribute.go (about) 1 package chmodhelper 2 3 import ( 4 "gitlab.com/evatix-go/core/issetter" 5 ) 6 7 type VarAttribute struct { 8 rawInput string 9 isFixedType bool 10 isRead issetter.Value 11 isWrite issetter.Value 12 isExecute issetter.Value 13 } 14 15 func (it *VarAttribute) IsFixedType() bool { 16 return it.isFixedType 17 } 18 19 func (it *VarAttribute) HasWildcard() bool { 20 return !it.isFixedType 21 } 22 23 // ToCompileFixAttr 24 // 25 // must check IsFixedType, before calling. 26 func (it *VarAttribute) ToCompileFixAttr() *Attribute { 27 if it.isFixedType { 28 return &Attribute{ 29 IsRead: it.isRead.IsTrue(), 30 IsWrite: it.isWrite.IsTrue(), 31 IsExecute: it.isExecute.IsTrue(), 32 } 33 } 34 35 return nil 36 } 37 38 // ToCompileAttr 39 // 40 // if fixed type then fixed param can be nil 41 func (it *VarAttribute) ToCompileAttr(fixed *Attribute) Attribute { 42 if it.isFixedType { 43 return Attribute{ 44 IsRead: it.isRead.IsTrue(), 45 IsWrite: it.isWrite.IsTrue(), 46 IsExecute: it.isExecute.IsTrue(), 47 } 48 } 49 50 return Attribute{ 51 IsRead: it.isRead.WildcardApply(fixed.IsRead), 52 IsWrite: it.isWrite.WildcardApply(fixed.IsWrite), 53 IsExecute: it.isExecute.WildcardApply(fixed.IsExecute), 54 } 55 } 56 57 func (it *VarAttribute) Clone() *VarAttribute { 58 if it == nil { 59 return nil 60 } 61 62 return &VarAttribute{ 63 rawInput: it.rawInput, 64 isFixedType: it.IsFixedType(), 65 isRead: it.isRead, 66 isWrite: it.isWrite, 67 isExecute: it.isExecute, 68 } 69 } 70 71 func (it *VarAttribute) IsEqualPtr(next *VarAttribute) bool { 72 if it == nil && next == nil { 73 return true 74 } 75 76 if it == nil || next == nil { 77 return false 78 } 79 80 isRead := next.isRead == it.isRead 81 isWrite := next.isWrite == it.isWrite 82 isExecute := next.isExecute == it.isExecute 83 84 return isRead && 85 isWrite && 86 isExecute 87 } 88 89 func (it *VarAttribute) String() string { 90 return it.rawInput 91 }