-
Notifications
You must be signed in to change notification settings - Fork 145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expose command line option to configure umask for directories and files #190
Open
mlusetti
wants to merge
4
commits into
restic:master
Choose a base branch
from
mlusetti:filemode-dirmode-option-support
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Feature: Implement boolean flag "group-readable-repositores" | ||
|
||
A CLI option to write dirs and files with a group readable permission grant | ||
|
||
https://github.com/restic/rest-server/issues/189 | ||
https://github.com/restic/rest-server/pull/190 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,8 +29,6 @@ | |
type Options struct { | ||
AppendOnly bool // if set, delete actions are not allowed | ||
Debug bool | ||
DirMode os.FileMode | ||
FileMode os.FileMode | ||
NoVerifyUpload bool | ||
|
||
// If set, we will panic when an internal server error happens. This | ||
|
@@ -39,29 +37,51 @@ | |
|
||
BlobMetricFunc BlobMetricFunc | ||
QuotaManager *quota.Manager | ||
FsyncWarning *sync.Once | ||
FsyncWarning *sync.Once | ||
|
||
// If set, we will panic when an internal server error happens. This | ||
// makes it easier to debug such errors. | ||
GroupReadable bool | ||
|
||
dirMode os.FileMode | ||
fileMode os.FileMode | ||
} | ||
|
||
// DefaultDirMode is the file mode used for directory creation if not | ||
// DefaultGroupReadable shows if files and dirs written should be group readable | ||
// overridden in the Options | ||
const DefaultGroupReadable = false | ||
|
||
// DefaultDirMode is the file mode used for directory creation by default | ||
const DefaultDirMode os.FileMode = 0700 | ||
|
||
// DefaultFileMode is the file mode used for file creation if not | ||
// overridden in the Options | ||
// DefaultFileMode is the file mode used for file creation by default | ||
const DefaultFileMode os.FileMode = 0600 | ||
|
||
// GroupReadableDirMode is the file mode used for directory creation if group readable | ||
const GroupReadableDirMode os.FileMode = 0750 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd prefer |
||
|
||
// GroupReadableFileMode is the file mode used for directory creation if group readable | ||
const GroupReadableFileMode os.FileMode = 0640 | ||
|
||
// New creates a new Handler for a single Restic backup repo. | ||
// path is the full filesystem path to this repo directory. | ||
// opt is a set of options. | ||
func New(path string, opt Options) (*Handler, error) { | ||
if path == "" { | ||
return nil, fmt.Errorf("path is required") | ||
} | ||
if opt.DirMode == 0 { | ||
opt.DirMode = DefaultDirMode | ||
} | ||
if opt.FileMode == 0 { | ||
opt.FileMode = DefaultFileMode | ||
// if opt.dirMode == 0 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we need these comments. |
||
// opt.dirMode = DefaultDirMode | ||
// } | ||
// if opt.fileMode == 0 { | ||
// opt.fileMode = DefaultFileMode | ||
// } | ||
if opt.GroupReadable { | ||
opt.dirMode = GroupReadableDirMode | ||
opt.fileMode = GroupReadableFileMode | ||
} else { | ||
opt.dirMode = DefaultDirMode | ||
opt.fileMode = DefaultFileMode | ||
} | ||
h := Handler{ | ||
path: path, | ||
|
@@ -289,7 +309,7 @@ | |
} | ||
cfg := h.getSubPath("config") | ||
|
||
f, err := os.OpenFile(cfg, os.O_CREATE|os.O_WRONLY|os.O_EXCL, h.opt.FileMode) | ||
f, err := os.OpenFile(cfg, os.O_CREATE|os.O_WRONLY|os.O_EXCL, h.opt.fileMode) | ||
if err != nil && os.IsExist(err) { | ||
if h.opt.Debug { | ||
log.Print(err) | ||
|
@@ -545,15 +565,15 @@ | |
} | ||
|
||
tmpFn := filepath.Join(filepath.Dir(path), objectID+".rest-server-temp") | ||
tf, err := tempFile(tmpFn, h.opt.FileMode) | ||
tf, err := tempFile(tmpFn, h.opt.fileMode) | ||
if os.IsNotExist(err) { | ||
// the error is caused by a missing directory, create it and retry | ||
mkdirErr := os.MkdirAll(filepath.Dir(path), h.opt.DirMode) | ||
mkdirErr := os.MkdirAll(filepath.Dir(path), h.opt.dirMode) | ||
if mkdirErr != nil { | ||
log.Print(mkdirErr) | ||
} else { | ||
// try again | ||
tf, err = tempFile(tmpFn, h.opt.FileMode) | ||
tf, err = tempFile(tmpFn, h.opt.fileMode) | ||
} | ||
} | ||
if err != nil { | ||
|
@@ -750,21 +770,21 @@ | |
|
||
log.Printf("Creating repository directories in %s\n", h.path) | ||
|
||
if err := os.MkdirAll(h.path, h.opt.DirMode); err != nil { | ||
if err := os.MkdirAll(h.path, h.opt.dirMode); err != nil { | ||
h.internalServerError(w, err) | ||
return | ||
} | ||
|
||
for _, d := range ObjectTypes { | ||
if err := os.Mkdir(filepath.Join(h.path, d), h.opt.DirMode); err != nil && !os.IsExist(err) { | ||
if err := os.Mkdir(filepath.Join(h.path, d), h.opt.dirMode); err != nil && !os.IsExist(err) { | ||
h.internalServerError(w, err) | ||
return | ||
} | ||
} | ||
|
||
for i := 0; i < 256; i++ { | ||
dirPath := filepath.Join(h.path, "data", fmt.Sprintf("%02x", i)) | ||
if err := os.Mkdir(dirPath, h.opt.DirMode); err != nil && !os.IsExist(err) { | ||
if err := os.Mkdir(dirPath, h.opt.dirMode); err != nil && !os.IsExist(err) { | ||
h.internalServerError(w, err) | ||
return | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That comment doesn't look like it belongs here.