first commit

This commit is contained in:
Beyhan Oğur
2026-04-26 21:52:23 +03:00
commit 880f412e2c
2662 changed files with 866266 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
//go:build windows
package update
import (
"fmt"
"os"
"path/filepath"
)
// atomicReplace replaces oldPath with newPath. On Windows, we cannot rename
// over a running executable directly, so we move the old binary aside first.
func atomicReplace(oldPath, newPath string) error {
backupPath := filepath.Join(filepath.Dir(oldPath), ".bifrost-old.exe")
os.Remove(backupPath) // clean up any previous backup
if err := os.Rename(oldPath, backupPath); err != nil {
return err
}
if err := os.Rename(newPath, oldPath); err != nil {
// Rollback — report if rollback also fails
if rbErr := os.Rename(backupPath, oldPath); rbErr != nil {
return fmt.Errorf("rename failed: %w; rollback also failed: %v (backup at %s)", err, rbErr, backupPath)
}
return err
}
os.Remove(backupPath)
return nil
}