-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
[19.03] handle close error on save #2631
Merged
thaJeztah
merged 2 commits into
docker:19.03
from
cpuguy83:19.03_handle_close_error_on_save
Jul 16, 2020
Merged
Changes from all commits
Commits
Show all changes
2 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
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,35 @@ | ||
// +build !windows | ||
|
||
package configfile | ||
|
||
import ( | ||
"os" | ||
"syscall" | ||
) | ||
|
||
// copyFilePermissions copies file ownership and permissions from "src" to "dst", | ||
// ignoring any error during the process. | ||
func copyFilePermissions(src, dst string) { | ||
var ( | ||
mode os.FileMode = 0600 | ||
uid, gid int | ||
) | ||
|
||
fi, err := os.Stat(src) | ||
if err != nil { | ||
return | ||
} | ||
if fi.Mode().IsRegular() { | ||
mode = fi.Mode() | ||
} | ||
if err := os.Chmod(dst, mode); err != nil { | ||
return | ||
} | ||
|
||
uid = int(fi.Sys().(*syscall.Stat_t).Uid) | ||
gid = int(fi.Sys().(*syscall.Stat_t).Gid) | ||
|
||
if uid > 0 && gid > 0 { | ||
_ = os.Chown(dst, uid, gid) | ||
} | ||
} |
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,5 @@ | ||
package configfile | ||
|
||
func copyFilePermissions(src, dst string) { | ||
// TODO implement for Windows | ||
} |
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.
Question: what would be the implementation for windows?
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.
Not sure how to copy permissions and/or ownership on Windows. Perhaps @simonferquel would know.
Also not sure if the problem that this was fixing happens on Windows as well
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.
Hmm, I am not sure about the correct "Windows" way to do that. But anyway I don't think it applies (when you create a file on Windows, by default you inherit ACLs from the parent directory).
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.
Thx! Perhaps I should update the comment and remove "todo"
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.
also renaming the function would be welcome, because on the windows implementation it does not do what it claims to do (in the general case it does not copy the permissions, which is fine in this specific case, but could be confusing in the future). Maybe renaming it to
replicateConfigFilePermissions
or something like this would be preferable.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.
Don't think it's needed to include "configfile" in the name, as it's already in this package, and in itself, it's not specific to configfiles.
I'll have a look for changing the comment (and possibly name) on master