filemode

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2021 License: MIT Imports: 5 Imported by: 6

Documentation

Index

Constants

View Source
const (
	SupportedLengthString = "3"
	SupportedLength       = 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

This section is empty.

Types

type AttrVariant

type AttrVariant byte

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

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 NewAttribute

func NewAttribute(isRead, isWrite, isExecute bool) Attribute

func NewAttributeUsingByte

func NewAttributeUsingByte(v byte) Attribute

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

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

func (Attribute) ToChar

func (attribute Attribute) ToChar() byte

func (Attribute) ToRwx

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

func (Attribute) ToRwxString

func (attribute Attribute) ToRwxString() string

func (Attribute) ToSpecificBytes

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

func (Attribute) ToSum

func (attribute Attribute) ToSum() byte

func (Attribute) ToVariant

func (attribute Attribute) ToVariant() AttrVariant

type AttributeValue

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

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"
	All                                 Variant = "777"
)

func (Variant) String

func (variant Variant) String() string

func (Variant) ToWrapper

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

type Wrapper

type Wrapper struct {
	Owner, Group, Other Attribute
}

func New

func New(mode string) (Wrapper, error)

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

func NewUsingAttrs

func NewUsingAttrs(owner, group, other Attribute) Wrapper

func NewUsingByte

func NewUsingByte(owner, group, other byte) Wrapper

each byte should not be more than 7

func NewUsingBytes

func NewUsingBytes(allBytes [3]byte) Wrapper

each byte should not be more than 7

func NewUsingFileMode

func NewUsingFileMode(fileMode os.FileMode) Wrapper

func NewUsingRwxes

func NewUsingRwxes(rwxrwxrwx string) (Wrapper, error)

Format "rwxrwxrwx" eg. owener all enabled only "rwx------" length must be 9 always.

func NewUsingVariant

func NewUsingVariant(variant Variant) (Wrapper, error)

func (Wrapper) ApplyChmod

func (wrapper Wrapper) ApplyChmod(fileOrDirectoryPath string) error

func (Wrapper) Bytes

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

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

func (Wrapper) Chars

func (wrapper Wrapper) Chars() [4]byte

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

func (Wrapper) MustApplyChmod

func (wrapper Wrapper) MustApplyChmod(fileOrDirectoryPath string)

func (Wrapper) String

func (wrapper Wrapper) String() string

func (Wrapper) ToFileMode

func (wrapper Wrapper) ToFileMode() os.FileMode

func (Wrapper) ToFileModeString

func (wrapper Wrapper) ToFileModeString() string

4 digit string 0rwx, example 0777

func (Wrapper) ToModeStr

func (wrapper Wrapper) ToModeStr() string

3 digit string, example 777

func (Wrapper) ToRwxes

func (wrapper Wrapper) ToRwxes() string

returns "-rwxrwxrwx"

func (Wrapper) ToRwxesChars

func (wrapper Wrapper) ToRwxesChars() []byte

func (Wrapper) ToUint32Octal

func (wrapper Wrapper) ToUint32Octal() uint32

Jump to

Keyboard shortcuts

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