Skip to content

Commit

Permalink
🐛 Improve importing .sy.zip #12825
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed Oct 18, 2024
1 parent ac4b052 commit 5efce9b
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions kernel/model/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,12 @@ func ImportSY(zipPath, boxID, toPath string) (err error) {
})
}

var replacements []string
for oldID, newID := range blockIDs {
replacements = append(replacements, oldID, newID)
}
blockIDReplacer := strings.NewReplacer(replacements...)

// 将关联的数据库文件移动到 data/storage/av/ 下
storage := filepath.Join(unzipRootPath, "storage")
storageAvDir := filepath.Join(storage, "av")
Expand Down Expand Up @@ -242,9 +248,7 @@ func ImportSY(zipPath, boxID, toPath string) (err error) {
for oldAvID, newAvID := range avIDs {
newData = bytes.ReplaceAll(newData, []byte(oldAvID), []byte(newAvID))
}
for oldID, newID := range blockIDs {
newData = bytes.ReplaceAll(newData, []byte(oldID), []byte(newID))
}
newData = []byte(blockIDReplacer.Replace(string(newData)))
if !bytes.Equal(data, newData) {
if writeErr := os.WriteFile(oldPath, newData, 0644); nil != writeErr {
logging.LogErrorf("write av file [%s] failed: %s", oldPath, writeErr)
Expand Down

0 comments on commit 5efce9b

Please sign in to comment.