Skip to content

Commit

Permalink
fix #246, 修复下载完毕不能自动删除临时文件
Browse files Browse the repository at this point in the history
  • Loading branch information
iikira committed Jun 26, 2018
1 parent 9a536d6 commit 10312dd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
9 changes: 5 additions & 4 deletions internal/pcscommand/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,15 @@ func downloadPrintFormat(load int) string {

func download(id int, downloadURL, savePath string, loadBalansers []string, client *requester.HTTPClient, cfg *downloader.Config, downloadOptions *DownloadOptions) error {
var (
newCfg = cfg.Copy()
file *os.File
writerAt io.WriterAt
err error
exitChan chan struct{}
)

if !cfg.IsTest {
cfg.InstanceStatePath = savePath + DownloadSuffix
if !newCfg.IsTest {
newCfg.InstanceStatePath = savePath + DownloadSuffix

// 创建下载的目录
dir := filepath.Dir(savePath)
Expand Down Expand Up @@ -119,7 +120,7 @@ func download(id int, downloadURL, savePath string, loadBalansers []string, clie
}()
}

if cfg.IsTest {
if newCfg.IsTest {
fmt.Fprintf(downloadOptions.Out, "[%d] 测试下载开始\n\n", id)
}

Expand Down Expand Up @@ -176,7 +177,7 @@ func download(id int, downloadURL, savePath string, loadBalansers []string, clie
}
}

if !cfg.IsTest {
if !newCfg.IsTest {
fmt.Fprintf(downloadOptions.Out, "[%d] 下载完成, 保存位置: %s\n", id, savePath)
} else {
fmt.Fprintf(downloadOptions.Out, "[%d] 测试下载结束\n", id)
Expand Down
6 changes: 6 additions & 0 deletions requester/downloader/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,9 @@ func (cfg *Config) Fix() {
cfg.MaxParallel = 1
}
}

//Copy 拷贝新的配置
func (cfg *Config) Copy() *Config {
newCfg := *cfg
return &newCfg
}

0 comments on commit 10312dd

Please sign in to comment.