chmodhelper

package
v0.5.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 17, 2021 License: MIT Imports: 14 Imported by: 17

Documentation

Index

Constants

View Source
const (
	SingleRwxLengthString            = "3"
	HyphenedRwxLength                = constants.ArbitraryCapacity10
	HyphenedRwxLengthString          = constants.N10String
	FullRwxLengthWithoutHyphenString = constants.N9String
	FullRwxLengthWithoutHyphen       = constants.ArbitraryCapacity9
	SingleRwxLength                  = 3
	ReadValue                        = 4
	WriteValue                       = 2
	ExecuteValue                     = 1
	ReadWriteValue                   = ReadValue + WriteValue
	ReadExecuteValue                 = ReadValue + ExecuteValue
	WriteExecuteValue                = WriteValue + ExecuteValue
	ReadWriteExecuteValue            = ReadValue + WriteValue + ExecuteValue

	OwnerIndex       = 0
	GroupIndex       = 1
	OtherIndex       = 2
	ReadChar    byte = 'r'
	WriteChar   byte = 'w'
	ExecuteChar byte = 'x'
)

Reference : https://ss64.com/bash/chmod.html

Variables

This section is empty.

Functions

func ExpendRwx added in v0.4.1

func ExpendRwx(rwx string) (r, w, x byte)

func GetExistingChmod

func GetExistingChmod(filePath string) (os.FileMode, error)

func GetRwxLengthError added in v0.4.1

func GetRwxLengthError(rwx string) error

func IsChmod added in v0.4.1

func IsChmod(location string, expectedHyphenedRwx string) bool

IsChmod expectedHyphenedRwx should be 10 chars example "-rwxrwxrwx"

func IsChmodEqualUsingRwxOwnerGroupOther added in v0.4.1

func IsChmodEqualUsingRwxOwnerGroupOther(
	location string,
	rwx *chmodins.RwxOwnerGroupOther,
) bool

func ParseRwxInstructionToStringRwx added in v0.4.1

func ParseRwxInstructionToStringRwx(
	rwxInstruction *chmodins.RwxOwnerGroupOther,
	isIncludeHyphen bool,
) string

func VerifyChmod added in v0.4.1

func VerifyChmod(location string, expectedHyphenedRwx string) error

VerifyChmod - expectedHyphenedRwx should be 10 chars example "-rwxrwxrwx"

func VerifyChmodPaths added in v0.4.1

func VerifyChmodPaths(
	locations *[]string,
	expectedHyphenedRwx string,
	isContinueOnError bool,
) error

func VerifyChmodUsingRwxOwnerGroupOther added in v0.4.1

func VerifyChmodUsingRwxOwnerGroupOther(
	location string,
	rwx *chmodins.RwxOwnerGroupOther,
) error

Types

type AttrVariant

type AttrVariant byte

AttrVariant

1 - Execute true 2 - Write true 3 - Write + Execute true 4 - Read true 5 - Read + Execute true 6 - Read + Write true 7 - Read + Write + Execute all true

const (
	Execute          AttrVariant = 1
	Write            AttrVariant = 2
	WriteExecute     AttrVariant = 3
	Read             AttrVariant = 4
	ReadExecute      AttrVariant = 5
	ReadWrite        AttrVariant = 6
	ReadWriteExecute AttrVariant = 7
)

func (AttrVariant) IsGreaterThan

func (attrVariant AttrVariant) IsGreaterThan(v byte) bool

IsGreaterThan v > byte(attrVariant)

func (AttrVariant) String

func (attrVariant AttrVariant) String() string

func (AttrVariant) ToAttribute

func (attrVariant AttrVariant) ToAttribute() Attribute

func (AttrVariant) Value

func (attrVariant AttrVariant) Value() byte

type Attribute

type Attribute struct {
	IsRead    bool
	IsWrite   bool
	IsExecute bool
}

func MergeRwxWildcardWithFixedRwx added in v0.4.1

func MergeRwxWildcardWithFixedRwx(
	existingRwx,
	rwxWildcardInput string,
) (
	fixedAttribute *Attribute,
	err error,
)

MergeRwxWildcardWithFixedRwx

  • existingRwx : Usually refers to fixed rwx values like "rwx", "--x", "-w-" etc.
  • rwxWildcardInput : Usually refers to fixed rwx values like "rw*", "*-x", "-w-" etc. Wildcard means keep the existing value as is.

func NewAttribute

func NewAttribute(isRead, isWrite, isExecute bool) Attribute

func NewAttributeUsingByte

func NewAttributeUsingByte(v byte) Attribute

NewAttributeUsingByte

1 - Execute true 2 - Write true 3 - Write + Execute true 4 - Read true 5 - Read + Execute true 6 - Read + Write true 7 - Read + Write + Execute all true

func NewAttributeUsingRwx

func NewAttributeUsingRwx(rwx string) Attribute

NewAttributeUsingRwx Length must be 3 "rwx" should be put for attributes. eg. read enable all disable : "r--" eg. write enable all disable : "-w-" eg. execute enable all disable : "--x" eg. all enabled : "rwx"

func NewAttributeUsingVariant

func NewAttributeUsingVariant(v AttrVariant) Attribute

func (Attribute) ToAttributeValue

func (attribute Attribute) ToAttributeValue() AttributeValue

func (Attribute) ToByte

func (attribute Attribute) ToByte() byte

ToByte refers to the compiled byte value in between 0-7

func (Attribute) ToRwx

func (attribute Attribute) ToRwx() [3]byte

func (Attribute) ToRwxString

func (attribute Attribute) ToRwxString() string

ToRwxString returns "rwx"

func (Attribute) ToSpecificBytes

func (attribute Attribute) ToSpecificBytes() (read, write, exe, sum byte)

func (Attribute) ToStringByte added in v0.4.4

func (attribute Attribute) ToStringByte() byte

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) ToSum

func (attribute Attribute) ToSum() byte

ToSum refers to the compiled byte value in between 0-7

func (Attribute) ToVariant

func (attribute Attribute) ToVariant() AttrVariant

type AttributeValue

type AttributeValue struct {
	Read, Write, Execute, Sum byte
}

type RwxInstructionExecutor added in v0.4.1

type RwxInstructionExecutor struct {
	// contains filtered or unexported fields
}

func ParseRwxInstructionToExecutor added in v0.4.1

func ParseRwxInstructionToExecutor(
	rwxInstruction *chmodins.RwxInstruction,
) (
	*RwxInstructionExecutor, error,
)

func (*RwxInstructionExecutor) ApplyOnPath added in v0.4.1

func (receiver *RwxInstructionExecutor) ApplyOnPath(location string) error

func (*RwxInstructionExecutor) ApplyOnPaths added in v0.4.1

func (receiver *RwxInstructionExecutor) ApplyOnPaths(locations *[]string) error

func (*RwxInstructionExecutor) CompiledRwxWrapperUsingFixedRwxWrapper added in v0.5.0

func (receiver *RwxInstructionExecutor) CompiledRwxWrapperUsingFixedRwxWrapper(
	wrapper *RwxWrapper,
) (*RwxWrapper, error)

func (*RwxInstructionExecutor) CompiledWrapper added in v0.4.1

func (receiver *RwxInstructionExecutor) CompiledWrapper(mode os.FileMode) (*RwxWrapper, error)

func (*RwxInstructionExecutor) IsFixedWrapper added in v0.4.1

func (receiver *RwxInstructionExecutor) IsFixedWrapper() bool

IsFixedWrapper true indicates no wildcard symbol

func (*RwxInstructionExecutor) IsVarWrapper added in v0.4.1

func (receiver *RwxInstructionExecutor) IsVarWrapper() bool

IsVarWrapper if it has any wildcard symbol in it

type RwxInstructionExecutors added in v0.4.1

type RwxInstructionExecutors struct {
	// contains filtered or unexported fields
}

func NewRwxInstructionExecutors added in v0.4.1

func NewRwxInstructionExecutors(capacity int) *RwxInstructionExecutors

func ParseBaseRwxInstructionsToExecutors added in v0.4.1

func ParseBaseRwxInstructionsToExecutors(
	baseRwxInstructions *chmodins.BaseRwxInstructions,
) (
	*RwxInstructionExecutors, error,
)

func ParseRwxInstructionsToExecutors added in v0.4.1

func ParseRwxInstructionsToExecutors(
	rwxInstructions *[]*chmodins.RwxInstruction,
) (
	*RwxInstructionExecutors, error,
)

func (*RwxInstructionExecutors) Add added in v0.4.1

func (receiver *RwxInstructionExecutors) Add(
	rwxInstructionExecutor *RwxInstructionExecutor,
) *RwxInstructionExecutors

Add skips nil

func (*RwxInstructionExecutors) Adds added in v0.4.1

func (receiver *RwxInstructionExecutors) Adds(
	rwxInstructionExecutors ...*RwxInstructionExecutor,
) *RwxInstructionExecutors

Adds skips nil

func (*RwxInstructionExecutors) ApplyOnPath added in v0.4.1

func (receiver *RwxInstructionExecutors) ApplyOnPath(location string) error

func (*RwxInstructionExecutors) ApplyOnPaths added in v0.4.1

func (receiver *RwxInstructionExecutors) ApplyOnPaths(locations *[]string) error

func (*RwxInstructionExecutors) Count added in v0.4.1

func (receiver *RwxInstructionExecutors) Count() int

func (*RwxInstructionExecutors) HasAnyItem added in v0.4.1

func (receiver *RwxInstructionExecutors) HasAnyItem() bool

func (*RwxInstructionExecutors) HasIndex added in v0.4.1

func (receiver *RwxInstructionExecutors) HasIndex(index int) bool

func (*RwxInstructionExecutors) IsEmpty added in v0.4.1

func (receiver *RwxInstructionExecutors) IsEmpty() bool

func (*RwxInstructionExecutors) Items added in v0.4.1

func (receiver *RwxInstructionExecutors) Items() *[]*RwxInstructionExecutor

func (*RwxInstructionExecutors) LastIndex added in v0.4.1

func (receiver *RwxInstructionExecutors) LastIndex() int

func (*RwxInstructionExecutors) Length added in v0.4.1

func (receiver *RwxInstructionExecutors) Length() int

type RwxVariableWrapper added in v0.4.4

type RwxVariableWrapper struct {
	Owner, Group, Other VarAttribute
	// contains filtered or unexported fields
}

func ParseRwxInstructionToVarWrapper added in v0.4.1

func ParseRwxInstructionToVarWrapper(
	rwxInstruction *chmodins.RwxInstruction,
) (
	*RwxVariableWrapper, error,
)

func ParseRwxOwnerGroupOtherToRwxVariableWrapper added in v0.4.4

func ParseRwxOwnerGroupOtherToRwxVariableWrapper(
	rwxInstruction *chmodins.RwxOwnerGroupOther,
) (
	*RwxVariableWrapper, error,
)

func (*RwxVariableWrapper) IsFixedType added in v0.4.4

func (varWrapper *RwxVariableWrapper) IsFixedType() bool

func (*RwxVariableWrapper) ToCompileFixedPtr added in v0.4.4

func (varWrapper *RwxVariableWrapper) ToCompileFixedPtr() *RwxWrapper

func (*RwxVariableWrapper) ToCompileWrapper added in v0.4.4

func (varWrapper *RwxVariableWrapper) ToCompileWrapper(fixed *RwxWrapper) RwxWrapper

ToCompileWrapper if Fixed type then fixed input can be nil.

func (*RwxVariableWrapper) ToCompileWrapperPtr added in v0.4.4

func (varWrapper *RwxVariableWrapper) ToCompileWrapperPtr(fixed *RwxWrapper) *RwxWrapper

ToCompileWrapperPtr if Fixed type then fixed input can be nil.

type RwxWrapper added in v0.4.4

type RwxWrapper struct {
	Owner, Group, Other Attribute
}

func GetExistingChmodRwxWrapper added in v0.5.0

func GetExistingChmodRwxWrapper(
	filePath string,
) (RwxWrapper, error)

func GetExistingChmodRwxWrapperMustPtr added in v0.5.0

func GetExistingChmodRwxWrapperMustPtr(
	filePath string,
) *RwxWrapper

func GetExistingChmodRwxWrapperPtr added in v0.5.0

func GetExistingChmodRwxWrapperPtr(
	filePath string,
) (*RwxWrapper, error)

func New

func New(mode string) (RwxWrapper, error)

New mode length needs to 3, not more not less mode chars should be digits only (0-7) example "777", "755", "655"

func NewUsingAttrVariants

func NewUsingAttrVariants(owner, group, other AttrVariant) RwxWrapper

func NewUsingAttrs

func NewUsingAttrs(owner, group, other Attribute) RwxWrapper

func NewUsingByte

func NewUsingByte(owner, group, other byte) RwxWrapper

NewUsingByte each byte should not be more than 7

func NewUsingBytes

func NewUsingBytes(allBytes [3]byte) RwxWrapper

NewUsingBytes each byte should not be more than 7

func NewUsingFileMode

func NewUsingFileMode(fileMode os.FileMode) RwxWrapper

func NewUsingFileModePtr added in v0.4.1

func NewUsingFileModePtr(fileMode os.FileMode) *RwxWrapper

func NewUsingHyphenedRwxFullString added in v0.4.4

func NewUsingHyphenedRwxFullString(hyphenedRwxRwxRwx string) (RwxWrapper, error)

NewUsingHyphenedRwxFullString Format "-rwxrwxrwx"

eg. owener all enabled only "-rwx------"

eg. group all enabled only "----rwx---"

length must be 10 always.

Reference: https://ss64.com/bash/chmod.html

func NewUsingRwxFullString added in v0.4.4

func NewUsingRwxFullString(rwxFullStringWithoutHyphen string) (RwxWrapper, error)

NewUsingRwxFullString Format "rwxrwxrwx"

eg. owener all enabled only "rwx------"

eg. group all enabled only "---rwx---"

length must be 9 always.

func NewUsingRwxOwnerGroupOther added in v0.4.4

func NewUsingRwxOwnerGroupOther(
	rwxOwnerGroupOther *chmodins.RwxOwnerGroupOther,
) (RwxWrapper, error)

func NewUsingVariant

func NewUsingVariant(variant Variant) (RwxWrapper, error)

func (RwxWrapper) ApplyChmod added in v0.4.4

func (wrapper RwxWrapper) ApplyChmod(
	fileOrDirectoryPath string,
	isSkipOnNonExist bool,
) error

func (RwxWrapper) Bytes added in v0.4.4

func (wrapper RwxWrapper) Bytes() [3]byte

Bytes return rwx, (Owner)(Group)(Other) byte values under 1-7

func (RwxWrapper) HasChmod added in v0.4.4

func (wrapper RwxWrapper) HasChmod(location string) bool

func (RwxWrapper) LinuxApplyRecursive added in v0.4.5

func (wrapper RwxWrapper) LinuxApplyRecursive(
	dirPath string,
	isSkipOnNonExist bool,
) error

LinuxApplyRecursive skip if it is a non dir path

func (RwxWrapper) MustApplyChmod added in v0.4.4

func (wrapper RwxWrapper) MustApplyChmod(fileOrDirectoryPath string)

func (RwxWrapper) String added in v0.4.4

func (wrapper RwxWrapper) String() string

func (RwxWrapper) ToCompiledOctalBytes3Digits added in v0.4.4

func (wrapper RwxWrapper) ToCompiledOctalBytes3Digits() [3]byte

ToCompiledOctalBytes3Digits return '0'(Owner + '0')(Group + '0')(Other + '0') eg. 777, 555, 755 NOT rwx return

owner -> (0 - 7 value)
group -> (0 - 7 value)
other -> (0 - 7 value)

func (RwxWrapper) ToCompiledOctalBytes4Digits added in v0.4.4

func (wrapper RwxWrapper) ToCompiledOctalBytes4Digits() [4]byte

ToCompiledOctalBytes4Digits return 0rwx, '0'(Owner + '0')(Group + '0')(Other + '0') eg. 0777, 0555, 0755 NOT 0rwx

func (RwxWrapper) ToCompiledSplitValues added in v0.4.4

func (wrapper RwxWrapper) ToCompiledSplitValues() (owner, group, other byte)

ToCompiledSplitValues return

owner -> (0 - 7 value)
group -> (0 - 7 value)
other -> (0 - 7 value)
eg. 777, 755 etc

func (RwxWrapper) ToFileMode added in v0.4.4

func (wrapper RwxWrapper) ToFileMode() os.FileMode

func (RwxWrapper) ToFileModeString added in v0.4.4

func (wrapper RwxWrapper) ToFileModeString() string

ToFileModeString 4 digit string 0rwx, example 0777

func (RwxWrapper) ToFullRwxValueString added in v0.4.4

func (wrapper RwxWrapper) ToFullRwxValueString() string

ToFullRwxValueString returns "-rwxrwxrwx"

func (RwxWrapper) ToFullRwxValuesChars added in v0.4.4

func (wrapper RwxWrapper) ToFullRwxValuesChars() []byte

ToFullRwxValuesChars "-rwxrwxrwx" Bytes values

func (RwxWrapper) ToRwxCompiledStr added in v0.4.4

func (wrapper RwxWrapper) ToRwxCompiledStr() string

ToRwxCompiledStr 3 digit string, example 777

func (RwxWrapper) ToRwxOwnerGroupOther added in v0.4.4

func (wrapper RwxWrapper) ToRwxOwnerGroupOther() *chmodins.RwxOwnerGroupOther

func (RwxWrapper) ToUint32Octal added in v0.4.4

func (wrapper RwxWrapper) ToUint32Octal() uint32

func (RwxWrapper) Verify added in v0.4.4

func (wrapper RwxWrapper) Verify(location string) error

func (RwxWrapper) VerifyPaths added in v0.4.4

func (wrapper RwxWrapper) VerifyPaths(location *[]string, isContinueOnError bool) error

type VarAttribute added in v0.4.1

type VarAttribute struct {
	// contains filtered or unexported fields
}

func ParseRwxToVarAttribute added in v0.4.1

func ParseRwxToVarAttribute(rwx string) (varAttribute *VarAttribute, err error)

func (*VarAttribute) IsFixedType added in v0.4.1

func (varAttribute *VarAttribute) IsFixedType() bool

func (*VarAttribute) ToCompileAttr added in v0.4.1

func (varAttribute *VarAttribute) ToCompileAttr(fixed *Attribute) Attribute

ToCompileAttr if fixed type then fixed param can be nil

func (*VarAttribute) ToCompileFixAttr added in v0.4.1

func (varAttribute *VarAttribute) ToCompileFixAttr() *Attribute

ToCompileFixAttr must check IsFixedType, before calling.

type Variant

type Variant string
const (
	AllRead                             Variant = "444"
	AllWrite                            Variant = "222"
	AllExecute                          Variant = "111"
	AllReadWrite                        Variant = "666"
	AllReadExecute                      Variant = "555"
	AllWriteExecute                     Variant = "333"
	OwnerAllReadWriteGroupOther         Variant = "755"
	ReadWriteOwnerReadGroupOther        Variant = "644"
	ReadWriteOwnerReadExecuteGroupOther Variant = "655"
	X111                                Variant = "111"
	X222                                Variant = "222"
	X333                                Variant = "333"
	X444                                Variant = "444"
	X555                                Variant = "555"
	X644                                Variant = "644"
	X655                                Variant = "655"
	X666                                Variant = "666"
	X677                                Variant = "677"
	X711                                Variant = "711"
	X722                                Variant = "722"
	X744                                Variant = "744"
	X755                                Variant = "755"
	X766                                Variant = "766"
	X777                                Variant = "777"
)

func (Variant) String

func (variant Variant) String() string

func (Variant) ToWrapper

func (variant Variant) ToWrapper() (RwxWrapper, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL