Compare commits

...

5 Commits

  1. 2
      scagent/core/UpFile.go
  2. 21
      scagent/util/fsutil.go
  3. 38
      vue/afvue/src/assets/main.css
  4. 23
      vue/afvue/src/views/Sfilecompare.vue

2
scagent/core/UpFile.go

@ -101,6 +101,8 @@ func (f *UpFileService) UnzipArchive(info FileInfo, reply *string) error {
}()
// 返回true的字符串
if retMsg := <-ret; retMsg == "uzok" {
// 删除zip文件
util.DeleteFile(info.FileName)
*reply = retMsg
}
return nil

21
scagent/util/fsutil.go

@ -14,6 +14,7 @@ import (
"path/filepath"
"scagent/config"
"strings"
"time"
"github.com/schollz/progressbar/v3"
"go.uber.org/zap"
@ -287,6 +288,17 @@ func DecompressZip(zpFname string, dirpath string) error {
os.MkdirAll(filePath, os.ModePerm)
continue
}
// 文件存在先备份再覆盖
if _, err := os.Stat(filePath); err == nil {
// 当前时间
currentTime := time.Now().Format("20060102_150405")
// 备份文件
backupPath := filePath + currentTime + "_bak"
if err := os.Rename(filePath, backupPath); err != nil {
return fmt.Errorf("failed to backup file (%v)", err)
}
continue
}
// 父文件夹开始创建目录
if err := os.MkdirAll(filepath.Dir(filePath), os.ModePerm); err != nil {
return fmt.Errorf("failed to make directory (%v)", err)
@ -385,6 +397,10 @@ func CompressToZip(dest string, currentPath string, paths []string) error {
return err
}
defer f.Close()
// 保留文件的原有的时间
header.Modified = info.ModTime()
// 保留文件的原有的权限
header.SetMode(info.Mode())
_, err = io.Copy(headerWriter, f)
return err
})
@ -416,3 +432,8 @@ func ReadConfig() {
}
config.G.Port = fmt.Sprintf("%d", iport)
}
// 删除文件
func DeleteFile(filePath string) error {
return os.Remove(filePath)
}

38
vue/afvue/src/assets/main.css

@ -87,4 +87,42 @@ a,
}
.tb-php{
background-position: 0px -852px;
}
/*
对话框
*/
.dialog{
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
float: left;
left: 0;
top: 0;
position: fixed;
animation: fadeOut 3s ease-in-out forwards;
}
.dialog .alert{
position: fixed;
top: 50%;
left: 50%;
transform: translateX(-50%);
padding: 10px 20px;
border-radius: 5px;
z-index: 9999;
/* 3s后消失 */
animation: fadeOut 3s ease-in-out forwards;
}
/** 同步成功提示 3s后消失*/
.alert-success{
/* display: none; */
background-color: #aee9bc;
color: #fff;
}
@keyframes fadeOut {
0% {
opacity: 1;
}
100% {
opacity: 0;
}
}

23
vue/afvue/src/views/Sfilecompare.vue

@ -91,6 +91,14 @@
</div>
<!-- 弹框提示 -->
<div class="dialog" v-if="dialogShow">
<div class="alert alert-success">
同步成功
</div>
</div>
</div>
</template>
@ -116,8 +124,7 @@ export default {
isMenuVisible: false, //
menuTop: 0, //
menuLeft: 0, //
dialogShow: false, //
isShowDir: false, //
}
},
@ -336,8 +343,18 @@ export default {
// build to schema
const pdata = new URLSearchParams(data)
//
SendZipFile(pdata).then(res=>{
SendZipFile(pdata).then(res=>{
console.log(res,"res")
// alert(res.status)
if(res.status == "200"){
//
this.dialogShow = true
// 3s
setTimeout(() => {
this.dialogShow = false
}, 3000);
}
// alert(res.data.reply)
//
this.selectedFiles = []
// pdata

Loading…
Cancel
Save