Explorar o código

:art: 改进导出 Data 压缩包过程 Fix https://github.com/siyuan-note/siyuan/issues/6961

Liang Ding %!s(int64=2) %!d(string=hai) anos
pai
achega
7e214231d9
Modificáronse 2 ficheiros con 22 adicións e 9 borrados
  1. 7 1
      kernel/api/export.go
  2. 15 8
      kernel/model/export.go

+ 7 - 1
kernel/api/export.go

@@ -57,7 +57,13 @@ func exportData(c *gin.Context) {
 	ret := gulu.Ret.NewResult()
 	defer c.JSON(http.StatusOK, ret)
 
-	zipPath := model.ExportData()
+	zipPath, err := model.ExportData()
+	if nil != err {
+		ret.Code = 1
+		ret.Msg = err.Error()
+		ret.Data = map[string]interface{}{"closeTimeout": 7000}
+		return
+	}
 	ret.Data = map[string]interface{}{
 		"zip": zipPath,
 	}

+ 15 - 8
kernel/model/export.go

@@ -125,25 +125,30 @@ func ExportDataInFolder(exportFolder string) (name string, err error) {
 	util.PushEndlessProgress(Conf.Language(65))
 	defer util.ClearPushProgress(100)
 
-	WaitForWritingFiles()
-
-	exportFolder = filepath.Join(exportFolder, util.CurrentTimeSecondsStr())
-	zipPath, err := exportData(exportFolder)
+	zipPath, err := ExportData()
 	if nil != err {
 		return
 	}
 	name = filepath.Base(zipPath)
+	targetZipPath := filepath.Join(exportFolder, name)
+	zipAbsPath := filepath.Join(util.TempDir, "export", name)
+	err = filelock.RoboCopy(zipAbsPath, targetZipPath)
+	if nil != err {
+		logging.LogErrorf("copy export zip from [%s] to [%s] failed: %s", zipAbsPath, targetZipPath, err)
+		return
+	}
+	if removeErr := os.Remove(zipAbsPath); nil != removeErr {
+		logging.LogErrorf("remove export zip failed: %s", removeErr)
+	}
 	return
 }
 
-func ExportData() (zipPath string) {
+func ExportData() (zipPath string, err error) {
 	util.PushEndlessProgress(Conf.Language(65))
 	defer util.ClearPushProgress(100)
 
-	WaitForWritingFiles()
-
 	exportFolder := filepath.Join(util.TempDir, "export", util.CurrentTimeSecondsStr())
-	zipPath, err := exportData(exportFolder)
+	zipPath, err = exportData(exportFolder)
 	if nil != err {
 		return
 	}
@@ -152,6 +157,8 @@ func ExportData() (zipPath string) {
 }
 
 func exportData(exportFolder string) (zipPath string, err error) {
+	WaitForWritingFiles()
+
 	baseFolderName := "data-" + util.CurrentTimeSecondsStr()
 	if err = os.MkdirAll(exportFolder, 0755); nil != err {
 		logging.LogErrorf("create export temp folder failed: %s", err)