Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gopkg.in/phayes/permbits.v0

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gopkg.in/phayes/permbits.v0

  • v0.0.0-20190612203442-39d7c581d2ee
  • Go
  • Socket score

Version published
Created
Source

GoDoc CircleCI Maintainability Test Coverage patreon flattr

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

Contributors

  1. Patrick Hayes (linkedin) (github) - Available for hire.

FAQs

Package last updated on 12 Jun 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc