From 67d6fb970fc3f2dbfa1c2bc18440379652d37017 Mon Sep 17 00:00:00 2001 From: sunwp <244372610@qq.com> Date: Wed, 16 Mar 2022 17:48:07 +0800 Subject: [PATCH] Fix empty client output path (#1159) * If the client output parameter is not specified, the client cannot automatically obtain the target file path Signed-off-by: sunwp <244372610@qq.com> --- client/config/dfget.go | 51 +++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 28 deletions(-) diff --git a/client/config/dfget.go b/client/config/dfget.go index 4f47d8483..3031d6c5b 100644 --- a/client/config/dfget.go +++ b/client/config/dfget.go @@ -163,34 +163,6 @@ func (cfg *ClientOption) Validate() error { } func (cfg *ClientOption) Convert(args []string) error { - var err error - - if cfg.Output, err = filepath.Abs(cfg.Output); err != nil { - return err - } - - if cfg.URL == "" && len(args) > 0 { - cfg.URL = args[0] - } - - if cfg.Digest != "" { - cfg.Tag = "" - } - - if cfg.Console { - cfg.ShowProgress = false - } - - return nil -} - -func (cfg *ClientOption) String() string { - js, _ := json.Marshal(cfg) - return string(js) -} - -// This function must be called after checkURL -func (cfg *ClientOption) checkOutput() error { if stringutils.IsBlank(cfg.Output) { url := strings.TrimRight(cfg.URL, "/") idx := strings.LastIndexByte(url, '/') @@ -207,7 +179,30 @@ func (cfg *ClientOption) checkOutput() error { } cfg.Output = absPath } + if cfg.URL == "" && len(args) > 0 { + cfg.URL = args[0] + } + if cfg.Digest != "" { + cfg.Tag = "" + } + + if cfg.Console { + cfg.ShowProgress = false + } + return nil +} + +func (cfg *ClientOption) String() string { + js, _ := json.Marshal(cfg) + return string(js) +} + +// This function must be called after checkURL +func (cfg *ClientOption) checkOutput() error { + if !filepath.IsAbs(cfg.Output) { + return fmt.Errorf("path[%s] is not absolute path", cfg.Output) + } outputDir, _ := path.Split(cfg.Output) if err := MkdirAll(outputDir, 0777, basic.UserID, basic.UserGroup); err != nil { return err