Sync updates with elichika
As of https://github.com/YumeMichi/elichika/commit/81a78e964dcdb8bb2d123237f966f95e7fba190e Signed-off-by: Yuan Si <do4suki@gmail.com>
This commit is contained in:
@@ -7,15 +7,23 @@ import (
|
||||
"encoding/hex"
|
||||
"math/rand"
|
||||
"os"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
rwMutex sync.RWMutex
|
||||
)
|
||||
|
||||
func PathExists(path string) bool {
|
||||
_, err := os.Stat(path)
|
||||
return err == nil || os.IsExist(err)
|
||||
}
|
||||
|
||||
func ReadAllText(path string) string {
|
||||
rwMutex.RLock()
|
||||
defer rwMutex.RUnlock()
|
||||
|
||||
b, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return ""
|
||||
@@ -24,6 +32,9 @@ func ReadAllText(path string) string {
|
||||
}
|
||||
|
||||
func WriteAllText(path, text string) {
|
||||
rwMutex.Lock()
|
||||
defer rwMutex.Unlock()
|
||||
|
||||
_ = os.WriteFile(path, []byte(text), 0644)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user