mirror of
https://github.com/kopia/kopia.git
synced 2026-04-27 17:41:16 -04:00
moved block cache to a subdirectory
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user