moved block cache to a subdirectory

This commit is contained in:
Jarek Kowalski
2018-04-23 19:56:01 -07:00
parent df7a9e217a
commit f94fcea14b
2 changed files with 34 additions and 9 deletions

View File

@@ -3,6 +3,7 @@
import (
"context"
"os"
"path/filepath"
"time"
"github.com/kopia/kopia/storage/filesystem"
@@ -31,13 +32,15 @@ func newBlockCache(ctx context.Context, st storage.Storage, caching CachingOptio
return nullBlockCache{st}, nil
}
if _, err := os.Stat(caching.CacheDirectory); os.IsNotExist(err) {
if err := os.MkdirAll(caching.CacheDirectory, 0700); err != nil {
blockCacheDir := filepath.Join(caching.CacheDirectory, "blocks")
if _, err := os.Stat(blockCacheDir); os.IsNotExist(err) {
if err := os.MkdirAll(blockCacheDir, 0700); err != nil {
return nil, err
}
}
cacheStorage, err := filesystem.New(context.Background(), &filesystem.Options{
Path: caching.CacheDirectory,
Path: blockCacheDir,
})
if err != nil {
return nil, err

View File

@@ -5,6 +5,7 @@
"encoding/json"
"fmt"
"io/ioutil"
"path/filepath"
"reflect"
"github.com/kopia/kopia/internal/scrubber"
@@ -18,15 +19,11 @@
func runStatusCommand(ctx context.Context, rep *repo.Repository) error {
fmt.Printf("Config file: %v\n", rep.ConfigFile)
entries, err := ioutil.ReadDir(rep.CacheDirectory)
fileCount, totalFileSize, err := scanCacheDir(filepath.Join(rep.CacheDirectory, "blocks"))
if err != nil {
fmt.Printf("Cache directory: %v (error: %v)\n", rep.CacheDirectory, err)
} else {
var totalSize int64
for _, e := range entries {
totalSize += e.Size()
}
fmt.Printf("Cache directory: %v (%v files, %v)\n", rep.CacheDirectory, len(entries), units.BytesStringBase2(totalSize))
fmt.Printf("Cache directory: %v (%v files, %v)\n", rep.CacheDirectory, fileCount, units.BytesStringBase2(totalFileSize))
}
fmt.Println()
@@ -64,6 +61,31 @@ func runStatusCommand(ctx context.Context, rep *repo.Repository) error {
return nil
}
func scanCacheDir(dirname string) (fileCount int, totalFileLength int64, err error) {
entries, err := ioutil.ReadDir(dirname)
if err != nil {
return 0, 0, err
}
for _, e := range entries {
if e.IsDir() {
subdir := filepath.Join(dirname, e.Name())
c, l, err2 := scanCacheDir(subdir)
if err2 != nil {
return 0, 0, err2
}
fileCount += c
totalFileLength += l
continue
}
fileCount++
totalFileLength += e.Size()
}
return
}
func init() {
statusCommand.Action(repositoryAction(runStatusCommand))
}