windows和linux路径修改

Former-commit-id: 54e5eee24cfe089fb275883bb48a775daa1554ac
This commit is contained in:
zhangwei 2023-05-24 16:46:06 +08:00
parent b3a0c91d5e
commit 095ccb44e4
2 changed files with 5 additions and 5 deletions

View File

@ -25,7 +25,7 @@ func ChunkImageHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
size, _ := strconv.ParseInt(r.PostFormValue("size"), 10, 64)
hash := r.PostFormValue("hash")
name := r.PostFormValue("name")
// 对比合并请求的文件大小和已上传文件夹大小
toSize, _ := getDirSize(path.Join(linuxUploadTempPath, hash))
if size != toSize {
fmt.Fprintf(w, "文件上传错误")
@ -51,7 +51,7 @@ func ChunkImageHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
wg.Add(filesCount)
for i := 0; i < filesCount; i++ {
// 这里一定要注意按顺序读取不然文件就会损坏
fileName := path.Join(chunksPath, "\\"+filesSort[strconv.Itoa(i)])
fileName := path.Join(chunksPath, "/"+filesSort[strconv.Itoa(i)])
data, err := ioutil.ReadFile(fileName)
fmt.Println(err)
fs.Write(data)
@ -59,7 +59,7 @@ func ChunkImageHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
wg.Done()
}
wg.Wait()
os.RemoveAll(path.Join(chunksPath, "\\"))
os.RemoveAll(path.Join(chunksPath, "/"))
defer fs.Close()
//// 加载镜像文件到docker

View File

@ -22,7 +22,7 @@ type LoadBody struct {
}
var windowsUploadTempPath = strings.ReplaceAll(path.Join(windowsUploadPath, "temp"), "/", "\\")
var linuxUploadTempPath = path.Join(windowsUploadPath)
var linuxUploadTempPath = path.Join(linuxUploadPath)
func UploadImageHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
@ -51,7 +51,7 @@ func UploadImageHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
if !isPathExists {
err = os.MkdirAll(chunksPath, os.ModePerm)
}
destFile, err := os.OpenFile(path.Join(chunksPath+"\\"+hash+"-"+index), syscall.O_CREAT|syscall.O_WRONLY, 0777)
destFile, err := os.OpenFile(path.Join(chunksPath+"/"+hash+"-"+index), syscall.O_CREAT|syscall.O_WRONLY, 0777)
reader := bufio.NewReader(file)
writer := bufio.NewWriter(destFile)
buf := make([]byte, 1024*1024) // 1M buf