Move restore functionality into khepri package

This commit is contained in:
Alexander Neumann committed 2014-08-11 23:14:40 +02:00
1 parent 2428843faa
commit d66996e648
3 files changed
+162 -144

No files matched your search

+18
View File
@@ -18,6 +18,7 @@ type Snapshot struct {
UID string `json:"uid,omitempty"`
GID string `json:"gid,omitempty"`
id ID `json:omit`
repo *Repository
}
func NewSnapshot(dir string) *Snapshot {
@@ -84,10 +85,27 @@ func LoadSnapshot(repo *Repository, id ID) (*Snapshot, error) {
}
sn.id = id
sn.repo = repo
return sn, nil
}
func (sn *Snapshot) RestoreAt(path string) error {
err := os.MkdirAll(path, 0700)
if err != nil {
return err
}
if sn.Tree == nil {
sn.Tree, err = NewTreeFromRepo(sn.repo, sn.Content)
if err != nil {
return err
}
}
return sn.Tree.CreateAt(path)
}
func (sn *Snapshot) ID() ID {
return sn.id
}