mirror of
https://github.com/kovidgoyal/kitty
synced 2026-06-08 14:18:26 +02:00
Micro optimisation
This commit is contained in:
@@ -287,10 +287,13 @@ func (dc *DiskCache) add(key string, items map[string][]byte) (err error) {
|
||||
for x, data := range items {
|
||||
p := filepath.Join(base, x)
|
||||
var before int64
|
||||
exists := false
|
||||
if s, err := os.Stat(p); err == nil {
|
||||
before = s.Size()
|
||||
exists = true
|
||||
}
|
||||
if len(data) == 0 {
|
||||
if exists {
|
||||
if err = os.Remove(p); err != nil {
|
||||
if !os.IsNotExist(err) {
|
||||
return
|
||||
@@ -298,10 +301,13 @@ func (dc *DiskCache) add(key string, items map[string][]byte) (err error) {
|
||||
err = nil
|
||||
}
|
||||
changed -= before
|
||||
}
|
||||
} else {
|
||||
// unlink the file so that writing to it does not change a
|
||||
// previously linked copy created by get()
|
||||
if exists {
|
||||
_ = os.Remove(p)
|
||||
}
|
||||
if err = os.WriteFile(p, data, 0o700); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user