mirror of
https://github.com/OliveTin/OliveTin
synced 2025-12-16 19:15:38 +00:00
Some checks failed
Build Snapshot / build-snapshot (push) Waiting to run
DevSkim / DevSkim (push) Waiting to run
Buf CI / buf (push) Has been cancelled
CodeQL / Analyze (go) (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
Codestyle checks / codestyle (push) Has been cancelled
39 lines
629 B
Go
39 lines
629 B
Go
package filehelper
|
|
|
|
import (
|
|
log "github.com/sirupsen/logrus"
|
|
"os"
|
|
"sync"
|
|
)
|
|
|
|
var writeFileMutex sync.Mutex
|
|
|
|
func WriteFile(filename string, out []byte) {
|
|
writeFileMutex.Lock()
|
|
|
|
defer writeFileMutex.Unlock()
|
|
|
|
if _, err := os.Stat(filename); os.IsNotExist(err) {
|
|
handle, err := os.Create(filename)
|
|
handle.Close()
|
|
|
|
if err != nil {
|
|
log.WithFields(log.Fields{
|
|
"error": err,
|
|
}).Errorf("Failed to create %v", filename)
|
|
|
|
return
|
|
}
|
|
|
|
}
|
|
|
|
err := os.WriteFile(filename, out, 0600)
|
|
|
|
if err != nil {
|
|
log.WithFields(log.Fields{
|
|
"error": err,
|
|
}).Errorf("Failed to write session to %v", filename)
|
|
return
|
|
}
|
|
}
|