Skip to content

Commit

Permalink
🎨 Saving doc "Access is denied" siyuan-note/insider#552
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed Jun 25, 2021
1 parent e202bec commit 6e02283
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions file.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ func (GuluFile) WriteFileSafer(writePath string, data []byte, perm os.FileMode)
}

if nil == err {
var renamed bool
for i := 0; i < 3; i++ {
err = os.Rename(f.Name(), writePath) // Windows 上重命名是非原子的
if nil == err {
renamed = true
break
}

Expand All @@ -54,6 +56,11 @@ func (GuluFile) WriteFileSafer(writePath string, data []byte, perm os.FileMode)
}
break
}

if !renamed {
// 直接写入
err = os.WriteFile(writePath, data, perm)
}
}

if nil != err {
Expand Down

0 comments on commit 6e02283

Please sign in to comment.