correctly handle configuration file saving when it is a relative symlink#5282
Conversation
d4a0fb0 to
c90705a
Compare
vvoland
left a comment
There was a problem hiding this comment.
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
vvoland
left a comment
There was a problem hiding this comment.
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.
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.
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 <me@woland.xyz> Co-authored-by: Sebastiaan van Stijn <github@gone.nl> Signed-off-by: Will Wang <willww64@gmail.com> Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
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)