mirror of
https://github.com/kopia/kopia.git
synced 2026-01-29 00:33:24 -05:00
disk cache: remove list after a write
fix close
This commit is contained in:
@@ -10,6 +10,7 @@ type blockCache interface {
|
||||
getBlock(blockID string, offset, length int64) ([]byte, error)
|
||||
putBlock(blockID string, data []byte) error
|
||||
listIndexBlocks() ([]Info, error)
|
||||
close() error
|
||||
}
|
||||
|
||||
// CachingOptions specifies configuration of local cache.
|
||||
|
||||
@@ -219,11 +219,8 @@ func (bm *Manager) ResetStats() {
|
||||
}
|
||||
|
||||
// Close closes block manager.
|
||||
func (bm *Manager) Close() error {
|
||||
if c, ok := bm.cache.(io.Closer); ok {
|
||||
return c.Close()
|
||||
}
|
||||
return nil
|
||||
func (bm *Manager) close() error {
|
||||
return bm.cache.close()
|
||||
}
|
||||
|
||||
func (bm *Manager) ensurePackGroupLocked(packGroup string, unpacked bool) *packInfo {
|
||||
|
||||
@@ -34,7 +34,7 @@ type diskBlockCache struct {
|
||||
}
|
||||
|
||||
func (c *diskBlockCache) getBlock(blockID string, offset, length int64) ([]byte, error) {
|
||||
fn := filepath.Join(c.directory, blockID) + cachedSuffix
|
||||
fn := c.cachedItemName(blockID)
|
||||
|
||||
b, err := ioutil.ReadFile(fn)
|
||||
if err == nil {
|
||||
@@ -89,12 +89,12 @@ func (c *diskBlockCache) putBlock(blockID string, data []byte) error {
|
||||
}
|
||||
|
||||
c.writeFileAtomic(filepath.Join(c.directory, blockID)+cachedSuffix, c.appendHMAC(data))
|
||||
|
||||
os.Remove(c.cachedItemName("list"))
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *diskBlockCache) listIndexBlocks() ([]Info, error) {
|
||||
cachedListFile := filepath.Join(c.directory, "list"+cachedSuffix)
|
||||
cachedListFile := c.cachedItemName("list")
|
||||
f, err := os.Open(cachedListFile)
|
||||
if err == nil {
|
||||
defer f.Close()
|
||||
@@ -121,6 +121,10 @@ func (c *diskBlockCache) listIndexBlocks() ([]Info, error) {
|
||||
return blocks, err
|
||||
}
|
||||
|
||||
func (c *diskBlockCache) cachedItemName(name string) string {
|
||||
return filepath.Join(c.directory, name+cachedSuffix)
|
||||
}
|
||||
|
||||
func (c *diskBlockCache) readBlocksFromCacheFile(f *os.File) ([]Info, error) {
|
||||
var blocks []Info
|
||||
data, err := ioutil.ReadAll(f)
|
||||
@@ -210,7 +214,7 @@ func (c *diskBlockCache) writeFileAtomic(fname string, contents []byte) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *diskBlockCache) lose() error {
|
||||
func (c *diskBlockCache) close() error {
|
||||
close(c.closed)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -33,3 +33,7 @@ func (c nullBlockCache) listIndexBlocks() ([]Info, error) {
|
||||
|
||||
return results, nil
|
||||
}
|
||||
|
||||
func (c nullBlockCache) close() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user