mirror of
https://github.com/octoleo/syncthing.git
synced 2024-12-23 03:18:59 +00:00
Use gzip compression for index cache
This commit is contained in:
parent
232d715c37
commit
89a5aac6ea
19
main.go
19
main.go
@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"compress/gzip"
|
||||||
"crypto/sha1"
|
"crypto/sha1"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"fmt"
|
"fmt"
|
||||||
@ -295,26 +296,36 @@ func updateLocalModel(m *Model) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func saveIndex(m *Model) {
|
func saveIndex(m *Model) {
|
||||||
name := fmt.Sprintf("%x.idx", sha1.Sum([]byte(m.Dir())))
|
name := fmt.Sprintf("%x.idx.gz", sha1.Sum([]byte(m.Dir())))
|
||||||
fullName := path.Join(opts.ConfDir, name)
|
fullName := path.Join(opts.ConfDir, name)
|
||||||
idxf, err := os.Create(fullName + ".tmp")
|
idxf, err := os.Create(fullName + ".tmp")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
protocol.WriteIndex(idxf, m.ProtocolIndex())
|
|
||||||
|
gzw := gzip.NewWriter(idxf)
|
||||||
|
|
||||||
|
protocol.WriteIndex(gzw, m.ProtocolIndex())
|
||||||
|
gzw.Close()
|
||||||
idxf.Close()
|
idxf.Close()
|
||||||
os.Rename(fullName+".tmp", fullName)
|
os.Rename(fullName+".tmp", fullName)
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadIndex(m *Model) {
|
func loadIndex(m *Model) {
|
||||||
fname := fmt.Sprintf("%x.idx", sha1.Sum([]byte(m.Dir())))
|
fname := fmt.Sprintf("%x.idx.gz", sha1.Sum([]byte(m.Dir())))
|
||||||
idxf, err := os.Open(path.Join(opts.ConfDir, fname))
|
idxf, err := os.Open(path.Join(opts.ConfDir, fname))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer idxf.Close()
|
defer idxf.Close()
|
||||||
|
|
||||||
idx, err := protocol.ReadIndex(idxf)
|
gzr, err := gzip.NewReader(idxf)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer gzr.Close()
|
||||||
|
|
||||||
|
idx, err := protocol.ReadIndex(gzr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user