Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0f1baeb

Browse files
committed
fix: updater may not be able to overwrite files directly
1 parent 16ff9e8 commit 0f1baeb

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

component/updater/update_core.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,16 @@ func (u *CoreUpdater) copyFile(src, dst string) (err error) {
437437
// otherwise truncates it before writing, without changing permissions.
438438
wc, err := os.OpenFile(dst, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, info.Mode())
439439
if err != nil {
440-
return fmt.Errorf("os.OpenFile(%s): %w", dst, err)
440+
// On some file system (such as Android's /data) maybe return error: "text file busy"
441+
// Let's delete the target file and recreate it
442+
err = os.Remove(dst)
443+
if err != nil {
444+
return fmt.Errorf("os.Remove(%s): %w", dst, err)
445+
}
446+
wc, err = os.OpenFile(dst, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, info.Mode())
447+
if err != nil {
448+
return fmt.Errorf("os.OpenFile(%s): %w", dst, err)
449+
}
441450
}
442451

443452
defer func() {

0 commit comments

Comments
 (0)