Handle write errors while saving index cache
This commit is contained in:
parent
23b27fa24a
commit
a0b15d006d
@ -567,7 +567,10 @@ func (m *Model) broadcastIndexLoop() {
|
|||||||
idx := m.protocolIndex(repo)
|
idx := m.protocolIndex(repo)
|
||||||
indexWg.Add(1)
|
indexWg.Add(1)
|
||||||
go func() {
|
go func() {
|
||||||
m.saveIndex(repo, m.indexDir, idx)
|
err := m.saveIndex(repo, m.indexDir, idx)
|
||||||
|
if err != nil {
|
||||||
|
l.Warnln("Saving index for %q: %v", repo, err)
|
||||||
|
}
|
||||||
indexWg.Done()
|
indexWg.Done()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
@ -688,7 +691,10 @@ func (m *Model) SaveIndexes(dir string) {
|
|||||||
m.rmut.RLock()
|
m.rmut.RLock()
|
||||||
for repo := range m.repoCfgs {
|
for repo := range m.repoCfgs {
|
||||||
fs := m.protocolIndex(repo)
|
fs := m.protocolIndex(repo)
|
||||||
m.saveIndex(repo, dir, fs)
|
err := m.saveIndex(repo, dir, fs)
|
||||||
|
if err != nil {
|
||||||
|
l.Warnln("Saving index for %q: %v", repo, err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
m.rmut.RUnlock()
|
m.rmut.RUnlock()
|
||||||
}
|
}
|
||||||
@ -702,26 +708,43 @@ func (m *Model) LoadIndexes(dir string) {
|
|||||||
m.rmut.RUnlock()
|
m.rmut.RUnlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Model) saveIndex(repo string, dir string, fs []protocol.FileInfo) {
|
func (m *Model) saveIndex(repo string, dir string, fs []protocol.FileInfo) error {
|
||||||
id := fmt.Sprintf("%x", sha1.Sum([]byte(m.repoCfgs[repo].Directory)))
|
id := fmt.Sprintf("%x", sha1.Sum([]byte(m.repoCfgs[repo].Directory)))
|
||||||
name := id + ".idx.gz"
|
name := id + ".idx.gz"
|
||||||
name = filepath.Join(dir, name)
|
name = filepath.Join(dir, name)
|
||||||
|
|
||||||
idxf, err := os.Create(name + ".tmp")
|
idxf, err := os.Create(name + ".tmp")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
gzw := gzip.NewWriter(idxf)
|
gzw := gzip.NewWriter(idxf)
|
||||||
|
|
||||||
protocol.IndexMessage{
|
n, err := protocol.IndexMessage{
|
||||||
Repository: repo,
|
Repository: repo,
|
||||||
Files: fs,
|
Files: fs,
|
||||||
}.EncodeXDR(gzw)
|
}.EncodeXDR(gzw)
|
||||||
|
if err != nil {
|
||||||
gzw.Close()
|
gzw.Close()
|
||||||
idxf.Close()
|
idxf.Close()
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
osutil.Rename(name+".tmp", name)
|
err = gzw.Close()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = idxf.Close()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if debug {
|
||||||
|
l.Debugln("wrote index,", n, "bytes uncompressed")
|
||||||
|
}
|
||||||
|
|
||||||
|
return osutil.Rename(name+".tmp", name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Model) loadIndex(repo string, dir string) []protocol.FileInfo {
|
func (m *Model) loadIndex(repo string, dir string) []protocol.FileInfo {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user