-
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add repo stats to restic package
- Loading branch information
1 parent
b8c2e81
commit 26d4724
Showing
11 changed files
with
348 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package cache | ||
|
||
import ( | ||
"fmt" | ||
|
||
v1 "github.com/garethgeorge/backrest/gen/go/v1" | ||
"go.etcd.io/bbolt" | ||
) | ||
|
||
type Cache struct { | ||
db *bbolt.DB | ||
} | ||
|
||
func NewCache(databasePath string) (*Cache, error) { | ||
db, err := bbolt.Open(databasePath, 0600, nil) | ||
if err != nil { | ||
return nil, fmt.Errorf("open database: %w", err) | ||
} | ||
return &Cache{db: db}, nil | ||
} | ||
|
||
func (c *Cache) Close() error { | ||
return c.db.Close() | ||
} | ||
|
||
func (c *Cache) SetRepoStats(repo *v1.Repo, stats *v1.RepoStats) error { | ||
return c.db.Update(func(tx *bbolt.Tx) error { | ||
b, err := tx.CreateBucketIfNotExists([]byte("repo_stats")) | ||
if err != nil { | ||
return fmt.Errorf("create bucket: %w", err) | ||
} | ||
return b.Put([]byte(repo.Id), protoutil.MustMarshal(stats)) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.