Skip to content
Snippets Groups Projects
Select Git revision
  • feature/v1.3.60
  • develop default protected
  • main protected
  • release/v1.0.7
  • release/v1.0.0
  • feature/v0.9.5
  • release/v0.6.2
  • hotfix/v0.5.7
  • release/v0.5.6
  • release/v0.5.5
  • hotfix/v0.5.4
  • hotfix/v0.5.3
  • hotfix/v0.5.2
  • release/v0.5.1
  • hotfix/v0.5.0
  • hotfix/v0.4.9
  • hotfix/v0.4.8
  • hotfix/v0.4.7
  • release/v0.4.6
  • hotfix/v0.4.5
  • v1.3.55
  • v1.3.52
  • v1.3.50
  • v1.3.45
  • v1.3.42
  • v1.3.41
  • v1.3.40
  • v1.3.38
  • v1.3.37
  • v1.3.36
  • v1.3.35
  • v1.3.34
  • v1.3.33
  • v1.3.32
  • v1.3.31
  • v1.3.30
  • v1.3.29
  • v1.3.28
  • v1.3.27
  • v1.3.26
40 results

Attribute.go

  • Md. Alim Ul Karim's avatar
    f1f0799b
    Merge branch 'feature/v0.6.1' into 'master' · f1f0799b
    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
    
    ![image](/uploads/fab52faf0a4919ea40cbf419859a1dcf/image.png)
    
    ## All Passing Tests
    
    ![image](/uploads/ce454d66170d421f276f14206faf4858/image.png)
    
    See merge request !52
    f1f0799b
    History
    Merge branch 'feature/v0.6.1' into 'master'
    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
    
    ![image](/uploads/fab52faf0a4919ea40cbf419859a1dcf/image.png)
    
    ## All Passing Tests
    
    ![image](/uploads/ce454d66170d421f276f14206faf4858/image.png)
    
    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
}