Select Git revision
Attribute.go
-
Md. Alim Ul Karim authored
hotfix/v0.6.2 : "Added integrated tests" "Fix chmod compare and verify issues" "new default methods or stirngs" "GetPathExistStat" hotfix/v0.6.2 : "Added integrated tests" "Fix chmod compare and verify issues" "new default methods or stirngs" "GetPathExistStat" ## Analysis  ## All Passing Tests  See merge request !52
Md. Alim Ul Karim authoredhotfix/v0.6.2 : "Added integrated tests" "Fix chmod compare and verify issues" "new default methods or stirngs" "GetPathExistStat" hotfix/v0.6.2 : "Added integrated tests" "Fix chmod compare and verify issues" "new default methods or stirngs" "GetPathExistStat" ## Analysis  ## All Passing Tests  See merge request !52
Attribute.go 2.76 KiB
package chmodhelper
import (
"gitlab.com/evatix-go/core/conditional"
"gitlab.com/evatix-go/core/constants"
)
type Attribute struct {
IsRead bool
IsWrite bool
IsExecute bool
}
func (attribute *Attribute) ToAttributeValue() AttributeValue {
read, write, exe, sum := attribute.ToSpecificBytes()
return AttributeValue{
Read: read,
Write: write,
Execute: exe,
Sum: sum,
}
}
func (attribute *Attribute) ToSpecificBytes() (read, write, exe, sum byte) {
read = conditional.Byte(attribute.IsRead, ReadValue, constants.Zero)
write = conditional.Byte(attribute.IsWrite, WriteValue, constants.Zero)
exe = conditional.Byte(attribute.IsExecute, ExecuteValue, constants.Zero)
return read, write, exe, read + write + exe
}
// ToByte refers to the compiled byte value in between 0-7
func (attribute *Attribute) ToByte() byte {
r := conditional.Byte(attribute.IsRead, ReadValue, constants.Zero)
w := conditional.Byte(attribute.IsWrite, WriteValue, constants.Zero)
e := conditional.Byte(attribute.IsExecute, ExecuteValue, constants.Zero)
return r + w + e
}
// ToSum refers to the compiled byte value in between 0-7
func (attribute *Attribute) ToSum() byte {
return attribute.ToByte()
}
func (attribute *Attribute) ToRwx() [3]byte {
return [3]byte{
conditional.Byte(attribute.IsRead, ReadChar, constants.HyphenChar),
conditional.Byte(attribute.IsWrite, WriteChar, constants.HyphenChar),
conditional.Byte(attribute.IsExecute, ExecuteChar, constants.HyphenChar),
}
}
// ToRwxString returns "rwx"
func (attribute *Attribute) ToRwxString() string {
rwxBytes := attribute.ToRwx()
return string(rwxBytes[:])
}
func (attribute *Attribute) ToVariant() AttrVariant {
b := attribute.ToByte()
return AttrVariant(b)
}
// ToStringByte returns the compiled byte value as Char byte value
//
// It is not restricted between 0-7 but 0-7 + char '0', which makes it string 0-7
func (attribute *Attribute) ToStringByte() byte {
return attribute.ToByte() + constants.ZeroChar
}
func (attribute *Attribute) Clone() *Attribute {
if attribute == nil {
return nil
}
return &Attribute{
IsRead: attribute.IsRead,
IsWrite: attribute.IsWrite,
IsExecute: attribute.IsExecute,
}
}
func (attribute *Attribute) IsEqualPtr(next *Attribute) bool {
if attribute == nil && next == nil {
return true
}
if attribute == nil || next == nil {
return false
}
isRead := attribute.IsRead == next.IsRead
isWrite := attribute.IsWrite == next.IsWrite
isExecute := attribute.IsExecute == next.IsExecute
return isRead &&
isWrite &&
isExecute
}
func (attribute Attribute) IsEqual(next Attribute) bool {
isRead := attribute.IsRead == next.IsRead
isWrite := attribute.IsWrite == next.IsWrite
isExecute := attribute.IsExecute == next.IsExecute
return isRead &&
isWrite &&
isExecute
}