| | |
| | | dirFiles, _ := ioutil.ReadDir(fileTmpPath) |
| | | if dirFiles != nil && len(dirFiles) == arg.TotalChunks { |
| | | //表示所有分块都上传了,需要merge |
| | | if !sv.MergeChunks(fileTmpPath, mergedFilePath) { |
| | | if !MergeChunks(fileTmpPath, mergedFilePath) { |
| | | return false |
| | | } |
| | | } |
| | |
| | | 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 |
| | |
| | | } |
| | | defer (*arg.File).Close() |
| | | if !util.CreateDirectory(configPatchPath) { |
| | | return false |
| | | return false, false |
| | | } |
| | | |
| | | filenameWithSuffix := path.Base(arg.Header.Filename) |
| | |
| | | fileTmpPath := configPatchPath + "/"+MD5Str |
| | | if !util.Exists(fileTmpPath) { |
| | | if !util.CreateDirectory(fileTmpPath) { |
| | | return false |
| | | return false, false |
| | | } |
| | | } |
| | | chunkAlignNum := util.FormatNum(arg.TotalChunks, arg.ChunkNumber) |
| | |
| | | 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) |
| | |
| | | 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) |
| | |
| | | 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 |
| | |
| | | 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 { |