From e034b17989d3bd4bfe807f7f7e7828176989a8f4 Mon Sep 17 00:00:00 2001
From: liuxiaolong <736321739@qq.com>
Date: 星期三, 18 十二月 2019 21:02:46 +0800
Subject: [PATCH] fix chunkAlignNum

---
 extend/util/util.go   |   13 +++++++++++++
 service/SysService.go |    8 +++++---
 2 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/extend/util/util.go b/extend/util/util.go
index 845ff42..224d086 100644
--- a/extend/util/util.go
+++ b/extend/util/util.go
@@ -296,4 +296,17 @@
 	}
 
 	return nil
+}
+
+func FormatNum(oNum int,n int) string {
+	m := 0
+	for {
+		oNum = oNum / 10
+		m++
+		if oNum == 0 {
+			break
+		}
+	}
+	fmtStr := "%0"+strconv.Itoa(m)+"d"
+	return fmt.Sprintf(fmtStr, n)
 }
\ No newline at end of file
diff --git a/service/SysService.go b/service/SysService.go
index 809693f..441a8a8 100644
--- a/service/SysService.go
+++ b/service/SysService.go
@@ -1,4 +1,5 @@
 package service
+
 import (
 	"basic.com/valib/logger.git"
 	"bufio"
@@ -7,7 +8,6 @@
 	"mime/multipart"
 	"os"
 	"os/exec"
-	"strconv"
 	"strings"
 	"webserver/extend/config"
 	"webserver/extend/util"
@@ -66,7 +66,8 @@
 		return true
 	}
 	//鍒ゆ柇鍒嗗潡鏂囦欢鏄惁瀛樺湪
-	chunkFilePath := fileTmpPath+"/"+arg.Identifier+"_"+strconv.Itoa(arg.ChunkNumber)
+	chunkAlignNum := util.FormatNum(arg.TotalChunks, arg.ChunkNumber)
+	chunkFilePath := fileTmpPath+"/"+arg.Identifier+"_"+chunkAlignNum
 	if !util.Exists(chunkFilePath) {
 		return false
 	}
@@ -110,7 +111,8 @@
 			return false
 		}
 	}
-	fileSavePath := fileTmpPath+"/"+MD5Str+"_"+strconv.Itoa(arg.ChunkNumber)
+	chunkAlignNum := util.FormatNum(arg.TotalChunks, arg.ChunkNumber)
+	fileSavePath := fileTmpPath+"/"+MD5Str+"_"+chunkAlignNum
 	if util.Exists(fileSavePath) {
 		rmErr := os.Remove(fileSavePath)
 		if rmErr != nil {

--
Gitblit v1.8.0