mirror of
https://github.com/restic/restic.git
synced 2025-12-10 06:01:49 +00:00
Refactor
This commit is contained in:
@@ -24,7 +24,7 @@ func hash(filename string) (khepri.ID, error) {
|
||||
}
|
||||
|
||||
func store_file(repo *khepri.Repository, path string) (khepri.ID, error) {
|
||||
obj, err := repo.NewObject(khepri.TYPE_BLOB)
|
||||
obj, idch, err := repo.Create(khepri.TYPE_BLOB)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -44,7 +44,7 @@ func store_file(repo *khepri.Repository, path string) (khepri.ID, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return obj.ID(), nil
|
||||
return <-idch, nil
|
||||
}
|
||||
|
||||
func archive_dir(repo *khepri.Repository, path string) (khepri.ID, error) {
|
||||
@@ -92,7 +92,7 @@ func archive_dir(repo *khepri.Repository, path string) (khepri.ID, error) {
|
||||
|
||||
log.Printf(" dir %q: %v entries", path, len(t.Nodes))
|
||||
|
||||
obj, err := repo.NewObject(khepri.TYPE_BLOB)
|
||||
obj, idch, err := repo.Create(khepri.TYPE_BLOB)
|
||||
|
||||
if err != nil {
|
||||
log.Printf("error creating object for tree: %v", err)
|
||||
@@ -106,7 +106,7 @@ func archive_dir(repo *khepri.Repository, path string) (khepri.ID, error) {
|
||||
|
||||
obj.Close()
|
||||
|
||||
id := obj.ID()
|
||||
id := <-idch
|
||||
log.Printf("tree for %q saved at %s", path, id)
|
||||
|
||||
return id, nil
|
||||
@@ -124,11 +124,15 @@ func commandBackup(repo *khepri.Repository, args []string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
sn := repo.NewSnapshot(target)
|
||||
sn := khepri.NewSnapshot(target)
|
||||
sn.Tree = id
|
||||
sn.Save()
|
||||
snid, err := sn.Save(repo)
|
||||
|
||||
fmt.Printf("%q archived as %v\n", target, sn.ID())
|
||||
if err != nil {
|
||||
log.Printf("error saving snapshopt: %v", err)
|
||||
}
|
||||
|
||||
fmt.Printf("%q archived as %v\n", target, snid)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"path"
|
||||
|
||||
@@ -49,7 +50,7 @@ func restore_file(repo *khepri.Repository, node khepri.Node, target string) erro
|
||||
|
||||
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)
|
||||
rd, err := repo.Get(khepri.TYPE_BLOB, id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -121,7 +122,12 @@ func commandRestore(repo *khepri.Repository, args []string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
err = restore_dir(repo, id, target)
|
||||
sn, err := khepri.LoadSnapshot(repo, id)
|
||||
if err != nil {
|
||||
log.Fatalf("error loading snapshot %s", id)
|
||||
}
|
||||
|
||||
err = restore_dir(repo, sn.Tree, target)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user