mirror of
https://github.com/restic/restic.git
synced 2025-10-21 14:49:28 +00:00
Refactor, add Object and Snapshot
This commit is contained in:
@@ -24,8 +24,9 @@ func hash(filename string) (khepri.ID, error) {
|
||||
return h.Sum([]byte{}), nil
|
||||
}
|
||||
|
||||
func archive_dir(repo *khepri.DirRepository, path string) (khepri.ID, error) {
|
||||
func archive_dir(repo *khepri.Repository, path string) (khepri.ID, error) {
|
||||
log.Printf("archiving dir %q", path)
|
||||
|
||||
dir, err := os.Open(path)
|
||||
if err != nil {
|
||||
log.Printf("open(%q): %v\n", path, err)
|
||||
@@ -81,7 +82,7 @@ func archive_dir(repo *khepri.DirRepository, path string) (khepri.ID, error) {
|
||||
return id, nil
|
||||
}
|
||||
|
||||
func commandBackup(repo *khepri.DirRepository, args []string) error {
|
||||
func commandBackup(repo *khepri.Repository, args []string) error {
|
||||
if len(args) != 1 {
|
||||
return errors.New("usage: backup dir")
|
||||
}
|
||||
@@ -93,7 +94,11 @@ func commandBackup(repo *khepri.DirRepository, args []string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Printf("%q archived as %v\n", target, id)
|
||||
sn := repo.NewSnapshot(target)
|
||||
sn.Tree = id
|
||||
sn.Save()
|
||||
|
||||
fmt.Printf("%q archived as %v\n", target, sn.ID())
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@@ -8,7 +8,7 @@ import (
|
||||
"github.com/fd0/khepri"
|
||||
)
|
||||
|
||||
func commandList(repo *khepri.DirRepository, args []string) error {
|
||||
func commandList(repo *khepri.Repository, args []string) error {
|
||||
if len(args) != 1 {
|
||||
return errors.New("usage: list [blob|ref]")
|
||||
}
|
||||
|
@@ -10,7 +10,7 @@ import (
|
||||
"github.com/fd0/khepri"
|
||||
)
|
||||
|
||||
func restore_file(repo *khepri.DirRepository, node khepri.Node, target string) error {
|
||||
func restore_file(repo *khepri.Repository, node khepri.Node, target string) error {
|
||||
fmt.Printf(" restore file %q\n", target)
|
||||
|
||||
rd, err := repo.Get(khepri.TYPE_BLOB, node.Content)
|
||||
@@ -47,7 +47,7 @@ func restore_file(repo *khepri.DirRepository, node khepri.Node, target string) e
|
||||
return nil
|
||||
}
|
||||
|
||||
func restore_dir(repo *khepri.DirRepository, id khepri.ID, target string) error {
|
||||
func restore_dir(repo *khepri.Repository, id khepri.ID, target string) error {
|
||||
fmt.Printf(" restore dir %q\n", target)
|
||||
rd, err := repo.Get(khepri.TYPE_REF, id)
|
||||
if err != nil {
|
||||
@@ -104,7 +104,7 @@ func restore_dir(repo *khepri.DirRepository, id khepri.ID, target string) error
|
||||
return nil
|
||||
}
|
||||
|
||||
func commandRestore(repo *khepri.DirRepository, args []string) error {
|
||||
func commandRestore(repo *khepri.Repository, args []string) error {
|
||||
if len(args) != 2 {
|
||||
return errors.New("usage: restore ID dir")
|
||||
}
|
||||
|
@@ -22,7 +22,7 @@ func errx(code int, format string, data ...interface{}) {
|
||||
os.Exit(code)
|
||||
}
|
||||
|
||||
type commandFunc func(*khepri.DirRepository, []string) error
|
||||
type commandFunc func(*khepri.Repository, []string) error
|
||||
|
||||
var commands map[string]commandFunc
|
||||
|
||||
@@ -61,7 +61,7 @@ func main() {
|
||||
errx(1, "unknown command: %q\n", cmd)
|
||||
}
|
||||
|
||||
repo, err := khepri.NewDirRepository(Opts.Repo)
|
||||
repo, err := khepri.NewRepository(Opts.Repo)
|
||||
|
||||
if err != nil {
|
||||
errx(1, "unable to create/open repo: %v", err)
|
||||
|
Reference in New Issue
Block a user