当前位置: 首页>>代码示例>>Golang>>正文


Golang repository.Repository类代码示例

本文整理汇总了Golang中restic/repository.Repository的典型用法代码示例。如果您正苦于以下问题:Golang Repository类的具体用法?Golang Repository怎么用?Golang Repository使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Repository类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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:MirkoDziadzka,项目名称:restic,代码行数:30,代码来源:checker.go

示例2: 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:fawick,项目名称:restic,代码行数:25,代码来源:cmd_backup.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:MirkoDziadzka,项目名称:restic,代码行数:30,代码来源:cmd_dump.go

示例4: listKeys

func listKeys(s *repository.Repository) error {
	tab := NewTable()
	tab.Header = fmt.Sprintf(" %-10s  %-10s  %-10s  %s", "ID", "User", "Host", "Created")
	tab.RowFormat = "%s%-10s  %-10s  %-10s  %s"

	done := make(chan struct{})
	defer close(done)

	for id := range s.List(restic.KeyFile, done) {
		k, err := repository.LoadKey(s, id.String())
		if err != nil {
			Warnf("LoadKey() failed: %v\n", err)
			continue
		}

		var current string
		if id.String() == s.KeyName() {
			current = "*"
		} else {
			current = " "
		}
		tab.Rows = append(tab.Rows, []interface{}{current, id.Str(),
			k.Username, k.Hostname, k.Created.Format(TimeFormat)})
	}

	return tab.Write(globalOptions.stdout)
}
开发者ID:ckemper67,项目名称:restic,代码行数:27,代码来源:cmd_key.go

示例5: 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 {
		blob, err := repo.Index().Lookup(id)
		if err != nil {
			return err
		}

		buf = buf[:cap(buf)]
		if uint(len(buf)) < blob.Length {
			buf = make([]byte, blob.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:fawick,项目名称:restic,代码行数:33,代码来源:node.go

示例6: saveTree

// saveTree saves a tree of fake files in the repo and returns the ID.
func saveTree(t testing.TB, repo *repository.Repository, seed int64) backend.ID {
	rnd := rand.NewSource(seed)
	numNodes := int(rnd.Int63() % 64)
	t.Logf("create %v nodes", numNodes)

	var tree Tree
	for i := 0; i < numNodes; i++ {
		seed := rnd.Int63() % maxSeed
		size := rnd.Int63() % maxFileSize

		node := &Node{
			Name: fmt.Sprintf("file-%v", seed),
			Type: "file",
			Mode: 0644,
			Size: uint64(size),
		}

		node.Content = saveFile(t, repo, fakeFile(t, seed, size))
		tree.Nodes = append(tree.Nodes, node)
	}

	id, err := repo.SaveJSON(pack.Tree, tree)
	if err != nil {
		t.Fatal(err)
	}

	return id
}
开发者ID:MirkoDziadzka,项目名称:restic,代码行数:29,代码来源:testing.go

示例7: loadBlob

func loadBlob(t *testing.T, repo *repository.Repository, id backend.ID, buf []byte) []byte {
	buf, err := repo.LoadBlob(pack.Data, id, buf)
	if err != nil {
		t.Fatalf("LoadBlob(%v) returned error %v", id, err)
	}

	return buf
}
开发者ID:MirkoDziadzka,项目名称:restic,代码行数:8,代码来源:archive_reader_test.go

示例8: listIndexIDs

func listIndexIDs(repo *repository.Repository) (list backend.IDs) {
	done := make(chan struct{})
	for id := range repo.List(backend.Index, done) {
		list = append(list, id)
	}

	return list
}
开发者ID:MirkoDziadzka,项目名称:restic,代码行数:8,代码来源:cmd_rebuild_index.go

示例9: 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:fawick,项目名称:restic,代码行数:9,代码来源:lock_test.go

示例10: 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:fawick,项目名称:restic,代码行数:10,代码来源:lock.go

示例11: 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 backend.ID{}, err
	}

	return backend.ParseID(name)
}
开发者ID:fawick,项目名称:restic,代码行数:11,代码来源:snapshot.go

示例12: 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:fawick,项目名称:restic,代码行数:9,代码来源:snapshot.go

示例13: 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:fawick,项目名称:restic,代码行数:10,代码来源:cmd_key.go

示例14: 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:fawick,项目名称:restic,代码行数:10,代码来源:checker_test.go

示例15: 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:fawick,项目名称:restic,代码行数:12,代码来源:repacker.go


注:本文中的restic/repository.Repository类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。