-
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
correctly handle configuration file saving when it is a relative symlink #5282
base: master
Are you sure you want to change the base?
Conversation
Signed-off-by: Will Wang <[email protected]>
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 61.46% 59.75% -1.71%
==========================================
Files 299 345 +46
Lines 20854 23430 +2576
==========================================
+ Hits 12818 14001 +1183
- Misses 7120 8455 +1335
- Partials 916 974 +58 |
use filepath.EvalSymlink instead of check with filepath.IsAbs Co-authored-by: Paweł Gronowski <[email protected]> Signed-off-by: Will Wang <[email protected]>
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
Signed-off-by: Will Wang <[email protected]>
Signed-off-by: Will Wang <[email protected]>
Signed-off-by: Will Wang <[email protected]>
Signed-off-by: Will Wang <[email protected]>
Signed-off-by: Will Wang <[email protected]>
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)
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)
}
}
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)