filemode

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2023 License: MIT Imports: 2 Imported by: 1

README

go-filemode

Go Reference Go Report Card

Get/change file mode bits on Linux systems.

Install

go get github.com/g0rbe/go-filemode

Documentation

Index

Constants

View Source
const (
	ReadUser  = S_IRUSR // Read user
	WriteUser = S_IWUSR // Write user
	ExecUser  = S_IXUSR // Execute user

	ReadGroup  = S_IRGRP // Read group
	WriteGroup = S_IWGRP // Write group
	ExecGroup  = S_IXGRP // Execute group

	ReadOther  = S_IROTH // Read other
	WriteOther = S_IWOTH // Write other
	ExecOther  = S_IXOTH // Execute other
)

Easy to use aliases

Variables

This section is empty.

Functions

func IsBlk

func IsBlk(m Mode) bool

IsBlk returns whether the file is a block special file (a device like a disk).

func IsBlkFile

func IsBlkFile(file *os.File) (bool, error)

IsBlkFile returns whether the file is a block special file (a device like a disk).

func IsBlkPath

func IsBlkPath(path string) (bool, error)

IsBlkPath returns whether the file in path is a block special file (a device like a disk).

func IsChr

func IsChr(m Mode) bool

IsChr returns whether the file is a character special file (a device like a terminal).

func IsChrFile

func IsChrFile(file *os.File) (bool, error)

IsChrFile returns whether the file is a character special file (a device like a terminal).

func IsChrPath

func IsChrPath(path string) (bool, error)

IsChrPath returns whether the file in path is a character special file (a device like a terminal).

func IsDir

func IsDir(m Mode) bool

IsDir returns whether the file is a directory.

func IsDirFile

func IsDirFile(file *os.File) (bool, error)

IsDirFile returns whether the file is a directory.

func IsDirPath

func IsDirPath(path string) (bool, error)

IsDirPath returns whether the file in path is a directory.

func IsFifo

func IsFifo(m Mode) bool

IsFifo returns whether the file is a FIFO special file, or a pipe.

func IsFifoFile

func IsFifoFile(file *os.File) (bool, error)

IsFifoFile returns whether the file is a FIFO special file, or a pipe.

func IsFifoPath

func IsFifoPath(path string) (bool, error)

IsFifoPath returns whether the file in path is a FIFO special file, or a pipe.

func IsLnk

func IsLnk(m Mode) bool

IsLnk returns whether the file is a symbolic link.

func IsLnkFile

func IsLnkFile(file *os.File) (bool, error)

IsLnkFile returns whether the file is a symbolic link.

func IsLnkPath

func IsLnkPath(path string) (bool, error)

IsLnkPath returns whether the file in path is a symbolic link.

func IsReg

func IsReg(m Mode) bool

IsReg returns whether the file is a regular file.

func IsRegFile

func IsRegFile(file *os.File) (bool, error)

IsRegFile returns whether the file is a regular file.

func IsRegPath

func IsRegPath(path string) (bool, error)

IsRegPath returns whether the file in path is a regular file.

func IsSet

func IsSet(mode, m Mode) bool

IsSet check whether m bit is set in mode.

func IsSetFile

func IsSetFile(file *os.File, m Mode) (bool, error)

IsSetFile checks whether the mode bit m is set in file.

func IsSetPath

func IsSetPath(path string, m Mode) (bool, error)

GetPath returns the mode of the file in path. This function does not follow symbolic link.

func IsSock

func IsSock(m Mode) bool

IsSock returns whether the file is a socket.

func IsSockFile

func IsSockFile(file *os.File) (bool, error)

IsSockFile returns whether the file is a socket.

func IsSockPath

func IsSockPath(path string) (bool, error)

IsSockPath returns whether the file in path is a socket.

func SetFile

func SetFile(file *os.File, m Mode) error

SetFile sets the mode bit m in file.

func SetPath

func SetPath(path string, m Mode) error

SetPath sets the mode bit m for file in path.

func UnsetFile

func UnsetFile(file *os.File, m Mode) error

UnsetFile unsets the mode bit m in file.

func UnsetPath

func UnsetPath(path string, m Mode) error

UnsetPath unsets the mode bit m for file in path.

Types

type Mode

type Mode uint32
const (
	S_IRUSR Mode = 0x00400 // Read permission bit for the owner of the file.
	S_IWUSR Mode = 0x00200 // Write permission bit for the owner of the file.
	S_IXUSR Mode = 0x00100 // Execute (for ordinary files) or search (for directories) permission bit for the owner of the file.
	S_IRWXU Mode = 0x00700 // This is equivalent to (S_IRUSR | S_IWUSR | S_IXUSR).

	S_IRGRP Mode = 0x00040 // Read permission bit for the group owner of the file.
	S_IWGRP Mode = 0x00020 // Write permission bit for the group owner of the file.
	S_IXGRP Mode = 0x00010 // Execute or search permission bit for the group owner of the file.
	S_IRWXG Mode = 0x00070 // This is equivalent to (S_IRGRP | S_IWGRP | S_IXGRP).

	S_IROTH Mode = 0x00004 // Read permission bit for other users.
	S_IWOTH Mode = 0x00002 // Write permission bit for other users.
	S_IXOTH Mode = 0x00001 // Execute or search permission bit for other users.
	S_IRWXO Mode = 0x00007 // This is equivalent to (S_IROTH | S_IWOTH | S_IXOTH).

	S_IFMT   Mode = 00170000 // This is a bit mask used to extract the file type code from a mode value.
	S_IFSOCK Mode = 0140000  // This is the file type constant of a socket.
	S_IFLNK  Mode = 0120000  // This is the file type constant of a symbolic link.
	S_IFREG  Mode = 0100000  // This is the file type constant of a regular file.
	S_IFBLK  Mode = 0060000  // This is the file type constant of a block-oriented device file.
	S_IFDIR  Mode = 0040000  // This is the file type constant of a directory file.
	S_IFCHR  Mode = 0020000  // This is the file type constant of a character-oriented device file.
	S_IFIFO  Mode = 0010000  // This is the file type constant of a FIFO or pipe.
	S_ISUID  Mode = 0004000  // This is the set-user-ID on execute bit.
	S_ISGID  Mode = 0002000  // This is the set-group-ID on execute bit.
	S_ISVTX  Mode = 0001000  // This is the sticky bit.
)

func GetFile

func GetFile(file *os.File) (Mode, error)

GetFile returns the file mode of file.

func GetPath

func GetPath(path string) (Mode, error)

GetPath returns the mode of the file in path. This function (and every *Path functions) does not follows symbolic link.

func Set

func Set(mode, m Mode) Mode

Set sets m bit in mode.

func Unset

func Unset(mode, m Mode) Mode

Unset unsets m bit in mode.

func (Mode) String

func (m Mode) String() string

Jump to

Keyboard shortcuts

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