backend: move backend implementation helpers to util package
This removes code that is only used within a backend implementation from the backend package. The latter now only contains code that also has external users.
This commit is contained in:
parent
8e6fdf5edf
commit
7881309d63
23 changed files with 158 additions and 135 deletions
29
internal/backend/util/paths.go
Normal file
29
internal/backend/util/paths.go
Normal file
|
@ -0,0 +1,29 @@
|
|||
package util
|
||||
|
||||
import "os"
|
||||
|
||||
type Modes struct {
|
||||
Dir os.FileMode
|
||||
File os.FileMode
|
||||
}
|
||||
|
||||
// DefaultModes defines the default permissions to apply to new repository
|
||||
// files and directories stored on file-based backends.
|
||||
var DefaultModes = Modes{Dir: 0700, File: 0600}
|
||||
|
||||
// DeriveModesFromFileInfo will, given the mode of a regular file, compute
|
||||
// the mode we should use for new files and directories. If the passed
|
||||
// error is non-nil DefaultModes are returned.
|
||||
func DeriveModesFromFileInfo(fi os.FileInfo, err error) Modes {
|
||||
m := DefaultModes
|
||||
if err != nil {
|
||||
return m
|
||||
}
|
||||
|
||||
if fi.Mode()&0040 != 0 { // Group has read access
|
||||
m.Dir |= 0070
|
||||
m.File |= 0060
|
||||
}
|
||||
|
||||
return m
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue