diff options
| author | chrislusf <chris.lu@gmail.com> | 2015-06-01 19:25:01 -0700 |
|---|---|---|
| committer | chrislusf <chris.lu@gmail.com> | 2015-06-01 19:25:01 -0700 |
| commit | 51aac49e82c8683801771729428a2dbffb09e5f6 (patch) | |
| tree | 0ad4d35917daa2fc246d8c520bece600b94e351c /go/weed/download.go | |
| parent | e09f45f5edd7786375598d2f6045f69be1b284c6 (diff) | |
| download | seaweedfs-51aac49e82c8683801771729428a2dbffb09e5f6.tar.xz seaweedfs-51aac49e82c8683801771729428a2dbffb09e5f6.zip | |
each command use its own options to avoid parameter collision
fix https://github.com/chrislusf/seaweedfs/issues/152
Diffstat (limited to 'go/weed/download.go')
| -rw-r--r-- | go/weed/download.go | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/go/weed/download.go b/go/weed/download.go index f08d64674..3c55b3a34 100644 --- a/go/weed/download.go +++ b/go/weed/download.go @@ -13,15 +13,18 @@ import ( ) var ( - downloadReplication *string - downloadDir *string + d DownloadOptions ) +type DownloadOptions struct { + server *string + dir *string +} + func init() { cmdDownload.Run = runDownload // break init cycle - cmdDownload.IsDebug = cmdDownload.Flag.Bool("debug", false, "verbose debug information") - server = cmdDownload.Flag.String("server", "localhost:9333", "SeaweedFS master location") - downloadDir = cmdDownload.Flag.String("dir", ".", "Download the whole folder recursively if specified.") + d.server = cmdDownload.Flag.String("server", "localhost:9333", "SeaweedFS master location") + d.dir = cmdDownload.Flag.String("dir", ".", "Download the whole folder recursively if specified.") } var cmdDownload = &Command{ @@ -40,7 +43,7 @@ var cmdDownload = &Command{ func runDownload(cmd *Command, args []string) bool { for _, fid := range args { - filename, content, e := fetchFileId(*server, fid) + filename, content, e := fetchFileId(*d.server, fid) if e != nil { fmt.Println("Fetch Error:", e) continue @@ -51,7 +54,7 @@ func runDownload(cmd *Command, args []string) bool { if strings.HasSuffix(filename, "-list") { filename = filename[0 : len(filename)-len("-list")] fids := strings.Split(string(content), "\n") - f, err := os.OpenFile(path.Join(*downloadDir, filename), os.O_WRONLY|os.O_CREATE|os.O_TRUNC, os.ModePerm) + f, err := os.OpenFile(path.Join(*d.dir, filename), os.O_WRONLY|os.O_CREATE|os.O_TRUNC, os.ModePerm) if err != nil { fmt.Println("File Creation Error:", e) continue @@ -59,7 +62,7 @@ func runDownload(cmd *Command, args []string) bool { defer f.Close() for _, partId := range fids { var n int - _, part, err := fetchFileId(*server, partId) + _, part, err := fetchFileId(*d.server, partId) if err == nil { n, err = f.Write(part) } @@ -72,7 +75,7 @@ func runDownload(cmd *Command, args []string) bool { } } } else { - ioutil.WriteFile(path.Join(*downloadDir, filename), content, os.ModePerm) + ioutil.WriteFile(path.Join(*d.dir, filename), content, os.ModePerm) } } return true |
