|
@@ -217,30 +217,32 @@ func ImportSY(zipPath, boxID, toPath string) (err error) {
|
|
|
newPath := filepath.Join(filepath.Dir(path), newAvID+".json")
|
|
|
renameAvPaths[path] = newPath
|
|
|
avIDs[oldAvID] = newAvID
|
|
|
+ return nil
|
|
|
+ })
|
|
|
|
|
|
- // 将数据库文件中的块 ID 替换为新的块 ID
|
|
|
- data, readErr := os.ReadFile(path)
|
|
|
+ // 重命名数据库文件
|
|
|
+ for oldPath, newPath := range renameAvPaths {
|
|
|
+ data, readErr := os.ReadFile(oldPath)
|
|
|
if nil != readErr {
|
|
|
- logging.LogErrorf("read av file [%s] failed: %s", path, readErr)
|
|
|
+ logging.LogErrorf("read av file [%s] failed: %s", oldPath, readErr)
|
|
|
return nil
|
|
|
}
|
|
|
- var newData []byte
|
|
|
- newData = data
|
|
|
- for oldID, newID := range avBlockIDs {
|
|
|
- newData = bytes.ReplaceAll(newData, []byte(oldID), []byte(newID))
|
|
|
+
|
|
|
+ // 将数据库文件中的块 ID 替换为新的块 ID
|
|
|
+ newData := data
|
|
|
+ for oldAvID, newAvID := range avIDs {
|
|
|
+ for oldID, newID := range avBlockIDs {
|
|
|
+ newData = bytes.ReplaceAll(newData, []byte(oldID), []byte(newID))
|
|
|
+ }
|
|
|
+ newData = bytes.ReplaceAll(newData, []byte(oldAvID), []byte(newAvID))
|
|
|
}
|
|
|
- newData = bytes.ReplaceAll(newData, []byte(oldAvID), []byte(newAvID))
|
|
|
if !bytes.Equal(data, newData) {
|
|
|
- if writeErr := os.WriteFile(path, newData, 0644); nil != writeErr {
|
|
|
- logging.LogErrorf("write av file [%s] failed: %s", path, writeErr)
|
|
|
+ if writeErr := os.WriteFile(oldPath, newData, 0644); nil != writeErr {
|
|
|
+ logging.LogErrorf("write av file [%s] failed: %s", oldPath, writeErr)
|
|
|
return nil
|
|
|
}
|
|
|
}
|
|
|
- return nil
|
|
|
- })
|
|
|
|
|
|
- // 重命名数据库文件
|
|
|
- for oldPath, newPath := range renameAvPaths {
|
|
|
if err = os.Rename(oldPath, newPath); nil != err {
|
|
|
logging.LogErrorf("rename av file from [%s] to [%s] failed: %s", oldPath, newPath, err)
|
|
|
return
|