Skip to content
/ permbits Public
forked from phayes/permbits

Easy file permissions for golang. Easily get and set file permission bits.

License

Notifications You must be signed in to change notification settings

kkrs/permbits

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GoDoc Build Status Coverage Status

PermBits

Easy file permissions for golang. Easily get and set file permission bits.

This package makes it a breeze to check and modify file permission bits in Linux, Mac, and other Unix systems.

##Example

permissions, err := permbits.Stat("/path/to/my/file")
if err != nil {
	return err
}

// Check to make sure the group can write to the file
// If they can't write, update the permissions so they can
if !permissions.GroupWrite() {
	permissions.SetGroupWrite(true)
	err := permbits.Chmod("/path/to/my/file", permissions)
	if err != nil {
		return errors.New("error setting permission on file", err)
	}
}

// Also works well with os.File
fileInfo, err := file.Stat()
if err != nil {
	return err
}
fileMode := fileInfo.Mode()
permissions := permbits.FileMode(fileMode)

// Disable write access to the file for everyone but the user
permissions.SetGroupWrite(false)
permissions.SetOtherWrite(false)
permbits.UpdateFileMode(&fileMode, permissions)

// You can also work with octets directly
if permissions != 0777 {
	return fmt.Errorf("Permissions on file are incorrect. Should be 777, got %o", permissions)
}

About

Easy file permissions for golang. Easily get and set file permission bits.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%