-
Notifications
You must be signed in to change notification settings - Fork 2k
correctly handle configuration file saving when it is a relative symlink #5282
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
correctly handle configuration file saving when it is a relative symlink #5282
Conversation
d4a0fb0
to
c90705a
Compare
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.
Thanks! I have just one suggestion to make the code simpler.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #5282 +/- ##
==========================================
+ Coverage 55.01% 55.04% +0.02%
==========================================
Files 361 361
Lines 30137 30142 +5
==========================================
+ Hits 16581 16591 +10
+ Misses 12598 12594 -4
+ Partials 958 957 -1 🚀 New features to boost your workflow:
|
d9c9095
to
115fdd9
Compare
The According to that test's comment, Docker CLI currently doesn't treat a dangling symlink as an error. However, After conducting local tests, I've compiled the following table:
In summary:
Update: |
115fdd9
to
c90705a
Compare
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.
Thanks, LGTM! (after squashing the commits)
cli/config/configfile/file.go
Outdated
cfgFile = f | ||
} else if os.IsNotExist(err) { | ||
// extract the path from the error if the configfile does not exist or is a dangling symlink | ||
cfgFile = err.(*os.PathError).Path |
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 if we can hit that situation, but this could panic, because os.IsNotExist
also considers syscall errors; https://go.dev/play/p/5VjH5lK-YDB
package main
import (
"os"
"syscall"
"testing"
)
func TestCheckError(t *testing.T) {
err := func() error {
return syscall.ENOENT
}()
if os.IsNotExist(err) {
t.Log(err)
cfgFile := err.(*os.PathError).Path
t.Log(cfgFile)
}
}
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.
Changed this to use errors.As
;
// extract the path from the error if the configfile does not exist or is a dangling symlink
var pathError *os.PathError
if errors.As(err, &pathError) {
cfgFile = pathError.Path
}
- use filepath.EvalSymlink instead of check with filepath.IsAbs - allow for dangling symlinks - extract path from error when NotExist error occurs Co-authored-by: Paweł Gronowski <[email protected]> Co-authored-by: Sebastiaan van Stijn <[email protected]> Signed-off-by: Will Wang <[email protected]> Signed-off-by: Sebastiaan van Stijn <[email protected]>
0118291
to
1015d15
Compare
@vvoland I rebased and squashed this one; also adjusted the error-matching; #5282 (comment) |
fixes: #5281
- What I did
Correctly hand the cases with config file being a relative symlink.
- How I did it
Check whether the result path of
os.Readlink(cfgFile)
is a relative path, if so, get the absolute path of it.- How to verify it
- Description for the changelog
- A picture of a cute animal (not mandatory but encouraged)