From 0d858e8610a79b15cb337daf134c4a00962dd477 Mon Sep 17 00:00:00 2001 From: liuxiaolong <liuxiaolong@aiotlink.com> Date: 星期四, 04 六月 2020 16:44:29 +0800 Subject: [PATCH] add sdk upload --- service/SysService.go | 24 ++++++++++++------------ 1 files changed, 12 insertions(+), 12 deletions(-) diff --git a/service/SysService.go b/service/SysService.go index 1a1f14c..62c1d04 100644 --- a/service/SysService.go +++ b/service/SysService.go @@ -77,7 +77,7 @@ dirFiles, _ := ioutil.ReadDir(fileTmpPath) if dirFiles != nil && len(dirFiles) == arg.TotalChunks { //琛ㄧず鎵�鏈夊垎鍧楅兘涓婁紶浜嗭紝闇�瑕乵erge - if !sv.MergeChunks(fileTmpPath, mergedFilePath) { + if !MergeChunks(fileTmpPath, mergedFilePath) { return false } } @@ -85,7 +85,7 @@ return true } -func (sv SysService) PatchUpload(arg *FileUploadVo) bool { +func (sv SysService) PatchUpload(arg *FileUploadVo) (bool,bool) { configPatchPath := "" if config.Server.PatchPath != "" { configPatchPath = config.Server.PatchPath @@ -94,7 +94,7 @@ } defer (*arg.File).Close() if !util.CreateDirectory(configPatchPath) { - return false + return false, false } filenameWithSuffix := path.Base(arg.Header.Filename) @@ -104,7 +104,7 @@ fileTmpPath := configPatchPath + "/"+MD5Str if !util.Exists(fileTmpPath) { if !util.CreateDirectory(fileTmpPath) { - return false + return false, false } } chunkAlignNum := util.FormatNum(arg.TotalChunks, arg.ChunkNumber) @@ -113,13 +113,13 @@ rmErr := os.Remove(fileSavePath) if rmErr != nil { logger.Debug("rmErr:",rmErr) - return false + return false, false } } file, e := os.Create(fileSavePath) if e !=nil { logger.Debug("os.Create err:",e,"fileSavePath:",fileSavePath) - return false + return false, false } defer file.Close() writer := bufio.NewWriter(file) @@ -127,12 +127,12 @@ n, err := (*arg.File).ReadAt(chunkData, 0) if n ==0 || err !=nil { logger.Debug("read chunkData err:",err,"n:",n) - return false + return false, false } nn, err2 := writer.Write(chunkData) if nn ==0 || err2 !=nil { logger.Debug("write chunkData err:",err2,"nn:",nn) - return false + return false, false } if err = writer.Flush(); err != nil { logger.Debug("write flush err:",err) @@ -143,13 +143,13 @@ isComplete = true } if isComplete { - if sv.MergeChunks(fileTmpPath,fileTmpPath + subfix) { + if MergeChunks(fileTmpPath,fileTmpPath + subfix) { logger.Debug("merge all chunks success,identifier:",MD5Str,"fileName:",arg.FileName) } else { - return false + return false, isComplete } } - return true + return true, isComplete } //upgrade @@ -267,7 +267,7 @@ return true } -func (sv SysService) MergeChunks(chunkPath string, storePath string) bool { +func MergeChunks(chunkPath string, storePath string) bool { var cmd *exec.Cmd cmd = exec.Command("/bin/sh", "-c", fmt.Sprintf("./mergeAll.sh %s %s", chunkPath, storePath)) if b, err := cmd.Output(); err != nil { -- Gitblit v1.8.0