do inplace rewrite for dion cookies to fix docker's EBUSY

This commit is contained in:
kulikov0 committed 2026-07-31 15:32:30 +02:00
1 parent d470aaee9b
commit 0f9f908874
3 files changed
+14 -1

No files matched your search

+10
View File
@@ -126,11 +126,21 @@ func (s *Session) SaveCookiesToFile(path string) error {
if err != nil {
return fmt.Errorf("marshal cookies: %w", err)
}
if atomicErr := writeFileAtomic(path, raw); atomicErr != nil {
if inPlaceErr := os.WriteFile(path, raw, 0o600); inPlaceErr != nil {
return fmt.Errorf("write cookies: %v, in-place fallback: %w", atomicErr, inPlaceErr)
}
}
return nil
}
func writeFileAtomic(path string, raw []byte) error {
tmp := path + ".tmp"
if err := os.WriteFile(tmp, raw, 0o600); err != nil {
return fmt.Errorf("write cookies tmp: %w", err)
}
if err := os.Rename(tmp, path); err != nil {
os.Remove(tmp)
return fmt.Errorf("rename cookies tmp: %w", err)
}
return nil