本文整理汇总了Golang中github.com/restic/restic/repository.Repository类的典型用法代码示例。如果您正苦于以下问题:Golang Repository类的具体用法?Golang Repository怎么用?Golang Repository使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Repository类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: packIDTester
func packIDTester(repo *repository.Repository, inChan <-chan backend.ID, errChan chan<- error, wg *sync.WaitGroup, done <-chan struct{}) {
debug.Log("Checker.testPackID", "worker start")
defer debug.Log("Checker.testPackID", "worker done")
defer wg.Done()
for id := range inChan {
ok, err := repo.Backend().Test(backend.Data, id.String())
if err != nil {
err = PackError{ID: id, Err: err}
} else {
if !ok {
err = PackError{ID: id, Err: errors.New("does not exist")}
}
}
if err != nil {
debug.Log("Checker.testPackID", "error checking for pack %s: %v", id.Str(), err)
select {
case <-done:
return
case errChan <- err:
}
continue
}
debug.Log("Checker.testPackID", "pack %s exists", id.Str())
}
}
开发者ID:hzensne1,项目名称:restic,代码行数:30,代码来源:checker.go
示例2: createFileAt
func (node Node) createFileAt(path string, repo *repository.Repository) error {
f, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY, 0600)
defer f.Close()
if err != nil {
return errors.Annotate(err, "OpenFile")
}
var buf []byte
for _, id := range node.Content {
_, _, _, length, err := repo.Index().Lookup(id)
if err != nil {
return err
}
buf = buf[:cap(buf)]
if uint(len(buf)) < length {
buf = make([]byte, length)
}
buf, err := repo.LoadBlob(pack.Data, id, buf)
if err != nil {
return errors.Annotate(err, "Load")
}
_, err = f.Write(buf)
if err != nil {
return errors.Annotate(err, "Write")
}
}
return nil
}
开发者ID:klauspost,项目名称:restic,代码行数:33,代码来源:node.go
示例3: printTrees
func printTrees(repo *repository.Repository, wr io.Writer) error {
done := make(chan struct{})
defer close(done)
trees := []backend.ID{}
for _, idx := range repo.Index().All() {
for blob := range idx.Each(nil) {
if blob.Type != pack.Tree {
continue
}
trees = append(trees, blob.ID)
}
}
for _, id := range trees {
tree, err := restic.LoadTree(repo, id)
if err != nil {
fmt.Fprintf(os.Stderr, "LoadTree(%v): %v", id.Str(), err)
continue
}
fmt.Fprintf(wr, "tree_id: %v\n", id)
prettyPrintJSON(wr, tree)
}
return nil
}
开发者ID:marete,项目名称:restic,代码行数:30,代码来源:cmd_dump.go
示例4: findLatestSnapshot
func findLatestSnapshot(repo *repository.Repository, targets []string) (backend.ID, error) {
var (
latest time.Time
latestID backend.ID
found bool
)
for snapshotID := range repo.List(backend.Snapshot, make(chan struct{})) {
snapshot, err := restic.LoadSnapshot(repo, snapshotID)
if err != nil {
return backend.ID{}, fmt.Errorf("Error listing snapshot: %v", err)
}
if snapshot.Time.After(latest) && samePaths(snapshot.Paths, targets) {
latest = snapshot.Time
latestID = snapshotID
found = true
}
}
if !found {
return backend.ID{}, errNoSnapshotFound
}
return latestID, nil
}
开发者ID:haswalt,项目名称:restic,代码行数:25,代码来源:cmd_backup.go
示例5: FindSnapshot
// FindSnapshot takes a string and tries to find a snapshot whose ID matches
// the string as closely as possible.
func FindSnapshot(repo *repository.Repository, s string) (backend.ID, error) {
// find snapshot id with prefix
name, err := backend.Find(repo.Backend(), backend.Snapshot, s)
if err != nil {
return nil, err
}
return backend.ParseID(name)
}
开发者ID:tharrisone,项目名称:restic,代码行数:11,代码来源:snapshot.go
示例6: LoadSnapshot
func LoadSnapshot(repo *repository.Repository, id backend.ID) (*Snapshot, error) {
sn := &Snapshot{id: id}
err := repo.LoadJSONUnpacked(backend.Snapshot, id, sn)
if err != nil {
return nil, err
}
return sn, nil
}
开发者ID:tharrisone,项目名称:restic,代码行数:9,代码来源:snapshot.go
示例7: LoadLock
// LoadLock loads and unserializes a lock from a repository.
func LoadLock(repo *repository.Repository, id backend.ID) (*Lock, error) {
lock := &Lock{}
if err := repo.LoadJSONUnpacked(backend.Lock, id, lock); err != nil {
return nil, err
}
lock.lockID = &id
return lock, nil
}
开发者ID:klauspost,项目名称:restic,代码行数:10,代码来源:lock.go
示例8: createFakeLock
func createFakeLock(repo *repository.Repository, t time.Time, pid int) (backend.ID, error) {
hostname, err := os.Hostname()
if err != nil {
return backend.ID{}, err
}
newLock := &restic.Lock{Time: t, PID: pid, Hostname: hostname}
return repo.SaveJSONUnpacked(backend.Lock, &newLock)
}
开发者ID:marete,项目名称:restic,代码行数:9,代码来源:lock_test.go
示例9: TeardownRepo
func TeardownRepo(t testing.TB, repo *repository.Repository) {
if !TestCleanup {
l := repo.Backend().(*local.Local)
t.Logf("leaving local backend at %s\n", l.Location())
return
}
OK(t, repo.Delete())
}
开发者ID:rawtaz,项目名称:restic,代码行数:9,代码来源:backend.go
示例10: LoadTree
func LoadTree(repo *repository.Repository, id backend.ID) (*Tree, error) {
tree := &Tree{}
err := repo.LoadJSONPack(pack.Tree, id, tree)
if err != nil {
return nil, err
}
return tree, nil
}
开发者ID:rawtaz,项目名称:restic,代码行数:9,代码来源:tree.go
示例11: addKey
func (cmd CmdKey) addKey(repo *repository.Repository) error {
id, err := repository.AddKey(repo, cmd.getNewPassword(), repo.Key())
if err != nil {
return fmt.Errorf("creating new key failed: %v\n", err)
}
cmd.global.Verbosef("saved new key as %s\n", id)
return nil
}
开发者ID:marete,项目名称:restic,代码行数:10,代码来源:cmd_key.go
示例12: list
func list(repo *repository.Repository, t backend.Type) (IDs []string) {
done := make(chan struct{})
defer close(done)
for id := range repo.List(t, done) {
IDs = append(IDs, id.String())
}
return IDs
}
开发者ID:hzensne1,项目名称:restic,代码行数:10,代码来源:checker_test.go
示例13: FindBlobsForPacks
// FindBlobsForPacks returns the set of blobs contained in a pack of packs.
func FindBlobsForPacks(repo *repository.Repository, packs backend.IDSet) (backend.IDSet, error) {
blobs := backend.NewIDSet()
for packID := range packs {
for _, packedBlob := range repo.Index().ListPack(packID) {
blobs.Insert(packedBlob.ID)
}
}
return blobs, nil
}
开发者ID:marete,项目名称:restic,代码行数:12,代码来源:repacker.go
示例14: TeardownRepo
func TeardownRepo(repo *repository.Repository) {
if !TestCleanup {
l := repo.Backend().(*local.Local)
fmt.Printf("leaving local backend at %s\n", l.Location())
return
}
err := repo.Delete()
if err != nil {
panic(err)
}
}
开发者ID:aut0,项目名称:restic,代码行数:12,代码来源:backend.go
示例15: saveRandomDataBlobs
// saveRandomDataBlobs generates random data blobs and saves them to the repository.
func saveRandomDataBlobs(t testing.TB, repo *repository.Repository, num int, sizeMax int) {
for i := 0; i < num; i++ {
size := mrand.Int() % sizeMax
buf := make([]byte, size)
_, err := io.ReadFull(rand.Reader, buf)
OK(t, err)
_, err = repo.SaveAndEncrypt(pack.Data, buf, nil)
OK(t, err)
}
}
开发者ID:marete,项目名称:restic,代码行数:13,代码来源:repository_test.go
示例16: deleteKey
func (cmd CmdKey) deleteKey(repo *repository.Repository, name string) error {
if name == repo.KeyName() {
return errors.New("refusing to remove key currently used to access repository")
}
err := repo.Backend().Remove(backend.Key, name)
if err != nil {
return err
}
cmd.global.Verbosef("removed key %v\n", name)
return nil
}
开发者ID:marete,项目名称:restic,代码行数:13,代码来源:cmd_key.go
示例17: RemoveStaleLocks
// RemoveStaleLocks deletes all locks detected as stale from the repository.
func RemoveStaleLocks(repo *repository.Repository) error {
return eachLock(repo, func(id backend.ID, lock *Lock, err error) error {
// ignore locks that cannot be loaded
if err != nil {
return nil
}
if lock.Stale() {
return repo.Backend().Remove(backend.Lock, id.String())
}
return nil
})
}
开发者ID:klauspost,项目名称:restic,代码行数:15,代码来源:lock.go
示例18: eachLock
func eachLock(repo *repository.Repository, f func(backend.ID, *Lock, error) error) error {
done := make(chan struct{})
defer close(done)
for id := range repo.List(backend.Lock, done) {
lock, err := LoadLock(repo, id)
err = f(id, lock, err)
if err != nil {
return err
}
}
return nil
}
开发者ID:klauspost,项目名称:restic,代码行数:14,代码来源:lock.go
示例19: FindPacksForBlobs
// FindPacksForBlobs returns the set of packs that contain the blobs.
func FindPacksForBlobs(repo *repository.Repository, blobs backend.IDSet) (backend.IDSet, error) {
packs := backend.NewIDSet()
idx := repo.Index()
for id := range blobs {
blob, err := idx.Lookup(id)
if err != nil {
return nil, err
}
packs.Insert(blob.PackID)
}
return packs, nil
}
开发者ID:marete,项目名称:restic,代码行数:15,代码来源:repacker.go
示例20: RepackBlobs
// RepackBlobs reads all blobs in blobIDs from src and saves them into new pack
// files in dst. Source and destination repo may be the same.
func RepackBlobs(src, dst *repository.Repository, blobIDs backend.IDSet) (err error) {
for id := range blobIDs {
err = repackBlob(src, dst, id)
if err != nil {
return err
}
}
err = dst.Flush()
if err != nil {
return err
}
return nil
}
开发者ID:marete,项目名称:restic,代码行数:17,代码来源:repacker.go
注:本文中的github.com/restic/restic/repository.Repository类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论