Skip to content
This repository has been archived by the owner on Feb 27, 2023. It is now read-only.

bugfix: infinite loop in dfget/config/config.go#checkOutput #1321

Merged
merged 1 commit into from
May 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dfget/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ func checkOutput(cfg *Config) error {
for dir := cfg.Output; !stringutils.IsEmptyStr(dir); dir = filepath.Dir(dir) {
if err := syscall.Access(dir, syscall.O_RDWR); err == nil {
break
} else if os.IsPermission(err) {
} else if os.IsPermission(err) || dir == "/" {
return fmt.Errorf("user[%s] path[%s] %v", cfg.User, cfg.Output, err)
}
}
Expand Down
3 changes: 3 additions & 0 deletions dfget/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ func (suite *ConfigSuite) TestAssertConfig(c *check.C) {
{clog: clog, url: "htt://a", checkFunc: errortypes.IsInvalidValue},
{clog: clog, url: "htt://a.b.com", checkFunc: errortypes.IsInvalidValue},
{clog: clog, url: "http://a.b.com", output: "/tmp/output", checkFunc: errortypes.IsNilError},
{clog: clog, url: "http://a.b.com", output: "./root", checkFunc: errortypes.IsNilError},
{clog: clog, url: "http://a.b.com", output: "/root", checkFunc: errortypes.IsInvalidValue},
{clog: clog, url: "http://a.b.com", output: "/", checkFunc: errortypes.IsInvalidValue},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also update test cases for TestCheckOutput.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}

var f = func() (err error) {
Expand Down Expand Up @@ -139,6 +141,7 @@ func (suite *ConfigSuite) TestCheckOutput(c *check.C) {
{"", "zj.test", j("zj.test")},
{"", "/tmp", ""},
{"", "/tmp/a/b/c/d/e/zj.test", "/tmp/a/b/c/d/e/zj.test"},
{"", "/", ""},
}

if cfg.User != "root" {
Expand Down