ch

package
v4.5.1 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Ch

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

Ch is used to chmod and chown files such that they match their desired group.

func New

func New(rs *RulesStore, logger log15.Logger) *Ch

New returns a Ch what will use your RulesStore to see what work needs to be done on the paths this Ch will receive when Do() is called on it.

Changes made will be logged to the given logger.

func (*Ch) Do

func (c *Ch) Do(path string, info fs.FileInfo) error

Do is a github.com/wtsi-ssg/wrstat/stat Operation that passes path to our PathCheck callback, and if it returns true, does the following chmod and chown-type behaviours, making use of the supplied Lstat info to avoid doing unnecessary repeated work:

1. Ensures that the GID of the path is the returned GID. 2. If path is a directory, ensures it has setgid applied (group sticky). 3. Ensures that User execute permission is set if group execute was set. 4. Ensures that group permissions match user permissions. 5. Forces user and group read and writeability.

Any errors are returned without logging them, except for "not exists" errors which are silently ignored since these are expected.

Any changes we do on disk are logged to our logger.

type Rule added in v4.3.0

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

Rule describes desired file and directory permissions and ownership.

func (*Rule) DesiredDirPerms added in v4.3.0

func (r *Rule) DesiredDirPerms(perms fs.FileMode) fs.FileMode

DesiredDirPerms returns the desired dir permissions as modified by the given current permissions.

func (*Rule) DesiredFilePerms added in v4.3.0

func (r *Rule) DesiredFilePerms(perms fs.FileMode) fs.FileMode

DesiredFilePerms returns the desired file permissions as modified by the given current permissions.

func (*Rule) DesiredGroup added in v4.3.0

func (r *Rule) DesiredGroup(gid uint32) uint32

DesiredGroup returns the desired group id if one was set, otherwise returns the given gid.

func (*Rule) DesiredUser added in v4.3.0

func (r *Rule) DesiredUser(uid uint32) uint32

DesiredUser returns the desired user id if one was set, otherwise returns the given uid.

type RulesStore added in v4.3.0

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

RulesStore holds permission and ownership changing rules for directories that can be retrieved by file path.

func NewRulesStore added in v4.3.0

func NewRulesStore() *RulesStore

NewRulesStore returns a new RulesStore. It can be chained with FromTSV().

func (*RulesStore) FromTSV added in v4.3.0

func (r *RulesStore) FromTSV(tsvReader *TSVReader) (*RulesStore, error)

FromTSV returns a RulesStore with rules taken from a ch.tsv via a TSVReader.

func (*RulesStore) Get added in v4.3.0

func (r *RulesStore) Get(path string) *Rule

Get returns the Rule for the longest directory containing the given path. Returns nil if no parent directory of the path is in the store.

type TSVReader added in v4.3.0

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

TSVReader is for parsing the custom ch.tsv file format, which has tab separated columns:

directory user group fileperms dirperms

*perms format is rwxrwxrwx for user,group,other, where - means remove the permission, * means leave it unchanged, and one of [rwx] means set it. s for the group x would enable setting group sticky bit. s implies x. Using ^ in at least 2 equivalent places to mean "set all if any set". ie. '**^**^***` would mean "change nothing, except if execute is set on user or group, set it on both".

user and group can be unix username or unix group name. * means don't set it. Use ^ to mean copy from the directory.

The file can have blank lines and comment lines that begin with #, which will be ignored.

func NewTSVReader added in v4.3.0

func NewTSVReader(r io.Reader) *TSVReader

NewTSVReader returns a new TSVReader which can read ch.tsv files.

func (*TSVReader) Columns added in v4.3.0

func (t *TSVReader) Columns() []string

Columns returns the columns of the row read after calling Next().

func (*TSVReader) Error added in v4.3.0

func (t *TSVReader) Error() error

Error returns any error encountered during Next() parsing. Does not generate an error at end of file.

func (*TSVReader) Next added in v4.3.0

func (t *TSVReader) Next() bool

Next reads the next line in the file, returning true if a valid row was read. Be sure to check Error() after this returns false, and do not continue to call after this returns false.

Jump to

Keyboard shortcuts

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