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

Commit

Permalink
bugfix: infinite loop in dfget/config/config.go#checkOutput
Browse files Browse the repository at this point in the history
Signed-off-by: lowzj <zj3142063@gmail.com>
  • Loading branch information
lowzj committed May 2, 2020
1 parent 8237693 commit dbc297d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
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},
}

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

0 comments on commit dbc297d

Please sign in to comment.