Browse Source

修正选中文件压缩失败的bug

master
xyiege 3 months ago
parent
commit
4738068363
  1. 3
      aufs/core/sendzip.go
  2. 5
      scagent/core/FileRpc.go
  3. 8
      scagent/util/fsutil.go
  4. 9
      vue/afvue/src/views/Sfilecompare.vue

3
aufs/core/sendzip.go

@ -34,6 +34,9 @@ func SendZip(w http.ResponseWriter, r *http.Request) {
// 文件
zipfarr := r.Form["sfiles"]
// zipfarr 切割成数组
zipfarr = strings.Split(zipfarr[0], ",")
// 选中的路径,可以为空
wtculpath := r.Form["curpath"]

5
scagent/core/FileRpc.go

@ -31,7 +31,7 @@ type ZipBlock struct {
}
// Upload 接收文件分片并写入到本地文件
func (f *FileService) Upload(chunk FileChunk, reply *bool) error {
func (f *FileService) Upload(chunk *FileChunk, reply *bool) error {
// 打开或创建文件,使用追加模式
file, err := os.OpenFile(chunk.FileName, os.O_WRONLY|os.O_CREATE, 0644)
if err != nil {
@ -61,13 +61,14 @@ func (f *FileService) Compress(args *ZipBlock, reply *string) error {
defer logger.Sync()
// 实际路径
realFilePath := filepath.Join(args.Basepath, args.Curpath)
logger.Info("Compress", zap.String("realFilePath", realFilePath))
// zip 文件名
zpFileName := "BIU_" + time.Now().Format("20060102_150405") + ".zip"
// 创建zip 异步?
taskId := make(chan string)
// 异步压缩
go func() {
util.CompressToZip(zpFileName, realFilePath, args.SelFile)
util.CompressToZip(zpFileName, realFilePath, args.Basepath, args.SelFile)
taskId <- "arcok"
// 日志输出
logger.Info("压缩文件", zap.String("filename", zpFileName), zap.String("path", realFilePath))

8
scagent/util/fsutil.go

@ -310,7 +310,8 @@ func DecompressZip(zpFname string) error {
// dest:目的地址以及压缩文件名 eg:/data/logZip/2022-12-12-log.zip
// paths:需要压缩的所有文件所组成的集合
func CompressToZip(dest string, currentPath string, paths []string) error {
func CompressToZip(dest string, currentPath string, basepath string, paths []string) error {
// fmt.Printf("paths len:%d\n", len(paths))
// fmt.Println("real path", currentPath)
// 打开files 目录
filesPath := ""
@ -336,7 +337,8 @@ func CompressToZip(dest string, currentPath string, paths []string) error {
// 从配置中读取到源目录
src = path.Join(currentPath, "/", src)
// 删除尾随路径(如果它是目录)
src := strings.TrimSuffix(src, string(os.PathSeparator))
src = strings.TrimSuffix(src, string(os.PathSeparator))
// fmt.Printf("zip src:%s\n", src)
// 文件遍历
err = filepath.Walk(src, func(path string, info os.FileInfo, err error) error {
if err != nil {
@ -350,7 +352,7 @@ func CompressToZip(dest string, currentPath string, paths []string) error {
// 监听的工作目录作为文件的结尾,然后取相对路径
// 在zip存档中设置文件的相对路径
header.Name, err = filepath.Rel(filepath.Dir(config.G.FilePath), path)
header.Name, err = filepath.Rel(filepath.Dir(basepath), path)
if err != nil {
return err
}

9
vue/afvue/src/views/Sfilecompare.vue

@ -331,12 +331,17 @@ export default {
}
// build to schema
const pdata = new URLSearchParams(data)
console.log(pdata,"pdata")
//
SendZipFile(pdata).then(res=>{
console.log(res,"res")
//
this.selectedFiles = []
// pdata
pdata.forEach((value, key) => {
pdata.delete(key)
})
})
return
},
//

Loading…
Cancel
Save