为task增加sourcepath,便于处理

This commit is contained in:
algotao
2025-07-25 12:04:16 +08:00
parent d1ad148725
commit a2bf3c853e
5 changed files with 303 additions and 63 deletions

View File

@@ -1,4 +1,5 @@
debug/
saastool
saastool_linux
cfg.toml
*.toml
test/

View File

@@ -7,6 +7,7 @@ import (
"fmt"
"os"
"path"
"path/filepath"
"runtime"
"sort"
"strings"
@@ -89,6 +90,7 @@ func RunTaskMake(args ...string) error {
TaskDescription: *desc,
Appid: *appid,
DataspaceId: *ds,
SourcePath: *sourcePath,
},
}
return doMakeHash(makeTaskParams, true)
@@ -207,10 +209,12 @@ func doTaskMake(makeTaskParams *makeTaskParams) error {
})
// 输出结果
relPath, _ := filepath.Rel(makeTaskParams.task.GetSourcePath(), makeTaskParams.sourcePath)
fileInfo := &saasapi.FileInfo{
FileName: makeTaskParams.sourcePath,
FileName: relPath,
FileSize: uint64(fi.Size()),
}
for _, r := range allResults {
fileInfo.FileBlocks = append(fileInfo.FileBlocks, &saasapi.FileBlock{
BlockSha256: r.hash,
@@ -219,6 +223,8 @@ func doTaskMake(makeTaskParams *makeTaskParams) error {
}
makeTaskParams.task.TaskFileInfos = append(makeTaskParams.task.TaskFileInfos, fileInfo)
makeTaskParams.task.TaskSize += uint64(fi.Size())
fmt.Println("")
return nil
}

View File

@@ -5,6 +5,7 @@ import (
"fmt"
"net/http"
"os"
"path/filepath"
"e.coding.net/rta/public/saasapi"
"e.coding.net/rta/public/saasapi/pkg/saashttp"
@@ -58,10 +59,10 @@ func doTaskUpload(uploadTaskParams uploadTaskParams) error {
return err
}
sourcePath := taskInfo.GetSourcePath()
totalFiles := len(taskInfo.GetTaskFileInfos())
fi := 0
for _, finfo := range taskInfo.GetTaskFileInfos() {
fi++
var f *os.File
offset := int64(0)
@@ -71,7 +72,11 @@ func doTaskUpload(uploadTaskParams uploadTaskParams) error {
bi++
if !binfo.GetUploaded() {
if f == nil {
f, err = os.Open(finfo.GetFileName())
fname := finfo.GetFileName()
if len(sourcePath) > 0 {
fname = filepath.Join(sourcePath, fname)
}
f, err = os.Open(fname)
if err != nil {
return err
}