fsx: Remove environment references
This commit removes the reference to the environment from the fsx package.
This commit is contained in:
parent
5a43ecfaeb
commit
3263920d6b
25 changed files with 167 additions and 183 deletions
|
|
@ -1,16 +1,37 @@
|
|||
// Package fsx provides additional file system functionality.
|
||||
//
|
||||
// Several functions in this package provide umask-ignoring functions.
|
||||
// Using these functions intervenes with the global umask.
|
||||
//
|
||||
// It is not safe to use functions provided by the standard go library concurrently with this function.
|
||||
// All functions in this package ignore the umask.
|
||||
// As such it is not safe to use otherwise equivalent functions provided by the standard go library concurrently with this package.
|
||||
// Users should take care that no other code in their application uses these functions.
|
||||
package fsx
|
||||
|
||||
import "io/fs"
|
||||
import (
|
||||
"io/fs"
|
||||
"sync"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
// DefaultFilePerm should be used by callers to use a consistent file mode for new files.
|
||||
const DefaultFilePerm fs.FileMode = 0666
|
||||
|
||||
// DefaultDirPerm should be used by callers to use a consistent mode for new directories.
|
||||
const DefaultDirPerm fs.FileMode = fs.ModeDir | fs.ModePerm
|
||||
// mask is the global mask lock
|
||||
var m mask
|
||||
|
||||
// mask allows disabling and re-enabling the global umask.
|
||||
// it is used by allow functions of this package.
|
||||
type mask struct {
|
||||
l sync.Mutex // locked?
|
||||
umask int // previous mask
|
||||
}
|
||||
|
||||
// Lock blocks until no other function is using this umask
|
||||
// and then sets it to 0.
|
||||
func (mask *mask) Lock() {
|
||||
mask.l.Lock()
|
||||
mask.umask = syscall.Umask(0)
|
||||
}
|
||||
|
||||
func (mask *mask) Unlock() {
|
||||
mask.umask = syscall.Umask(mask.umask)
|
||||
mask.l.Unlock()
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue