forked from TrueCloudLab/restic
restic: hide findLatestSnapshot
This commit is contained in:
parent
fcad5e6f5d
commit
61e827ae4f
2 changed files with 6 additions and 6 deletions
|
@ -12,8 +12,8 @@ import (
|
||||||
// ErrNoSnapshotFound is returned when no snapshot for the given criteria could be found.
|
// ErrNoSnapshotFound is returned when no snapshot for the given criteria could be found.
|
||||||
var ErrNoSnapshotFound = errors.New("no snapshot found")
|
var ErrNoSnapshotFound = errors.New("no snapshot found")
|
||||||
|
|
||||||
// FindLatestSnapshot finds latest snapshot with optional target/directory, tags, hostname, and timestamp filters.
|
// findLatestSnapshot finds latest snapshot with optional target/directory, tags, hostname, and timestamp filters.
|
||||||
func FindLatestSnapshot(ctx context.Context, be Lister, loader LoaderUnpacked, targets []string,
|
func findLatestSnapshot(ctx context.Context, be Lister, loader LoaderUnpacked, targets []string,
|
||||||
tagLists []TagList, hostnames []string, timeStampLimit *time.Time) (ID, error) {
|
tagLists []TagList, hostnames []string, timeStampLimit *time.Time) (ID, error) {
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
|
@ -91,7 +91,7 @@ func FindSnapshot(ctx context.Context, be Lister, s string) (ID, error) {
|
||||||
|
|
||||||
func FindFilteredSnapshot(ctx context.Context, be Lister, loader LoaderUnpacked, hosts []string, tags []TagList, paths []string, timeStampLimit *time.Time, snapshotID string) (ID, error) {
|
func FindFilteredSnapshot(ctx context.Context, be Lister, loader LoaderUnpacked, hosts []string, tags []TagList, paths []string, timeStampLimit *time.Time, snapshotID string) (ID, error) {
|
||||||
if snapshotID == "latest" {
|
if snapshotID == "latest" {
|
||||||
id, err := FindLatestSnapshot(ctx, be, loader, paths, tags, hosts, timeStampLimit)
|
id, err := findLatestSnapshot(ctx, be, loader, paths, tags, hosts, timeStampLimit)
|
||||||
if err == ErrNoSnapshotFound {
|
if err == ErrNoSnapshotFound {
|
||||||
err = fmt.Errorf("snapshot filter (Paths:%v Tags:%v Hosts:%v): %w", paths, tags, hosts, err)
|
err = fmt.Errorf("snapshot filter (Paths:%v Tags:%v Hosts:%v): %w", paths, tags, hosts, err)
|
||||||
}
|
}
|
||||||
|
@ -124,7 +124,7 @@ func FindFilteredSnapshots(ctx context.Context, be Lister, loader LoaderUnpacked
|
||||||
|
|
||||||
usedFilter = true
|
usedFilter = true
|
||||||
|
|
||||||
id, err = FindLatestSnapshot(ctx, be, loader, paths, tags, hosts, nil)
|
id, err = findLatestSnapshot(ctx, be, loader, paths, tags, hosts, nil)
|
||||||
if err == ErrNoSnapshotFound {
|
if err == ErrNoSnapshotFound {
|
||||||
err = errors.Errorf("no snapshot matched given filter (Paths:%v Tags:%v Hosts:%v)", paths, tags, hosts)
|
err = errors.Errorf("no snapshot matched given filter (Paths:%v Tags:%v Hosts:%v)", paths, tags, hosts)
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@ func TestFindLatestSnapshot(t *testing.T) {
|
||||||
restic.TestCreateSnapshot(t, repo, parseTimeUTC("2017-07-07 07:07:07"), 1, 0)
|
restic.TestCreateSnapshot(t, repo, parseTimeUTC("2017-07-07 07:07:07"), 1, 0)
|
||||||
latestSnapshot := restic.TestCreateSnapshot(t, repo, parseTimeUTC("2019-09-09 09:09:09"), 1, 0)
|
latestSnapshot := restic.TestCreateSnapshot(t, repo, parseTimeUTC("2019-09-09 09:09:09"), 1, 0)
|
||||||
|
|
||||||
id, err := restic.FindLatestSnapshot(context.TODO(), repo.Backend(), repo, []string{}, []restic.TagList{}, []string{"foo"}, nil)
|
id, err := restic.FindFilteredSnapshot(context.TODO(), repo.Backend(), repo, []string{"foo"}, []restic.TagList{}, []string{}, nil, "latest")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("FindLatestSnapshot returned error: %v", err)
|
t.Fatalf("FindLatestSnapshot returned error: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ func TestFindLatestSnapshotWithMaxTimestamp(t *testing.T) {
|
||||||
|
|
||||||
maxTimestamp := parseTimeUTC("2018-08-08 08:08:08")
|
maxTimestamp := parseTimeUTC("2018-08-08 08:08:08")
|
||||||
|
|
||||||
id, err := restic.FindLatestSnapshot(context.TODO(), repo.Backend(), repo, []string{}, []restic.TagList{}, []string{"foo"}, &maxTimestamp)
|
id, err := restic.FindFilteredSnapshot(context.TODO(), repo.Backend(), repo, []string{"foo"}, []restic.TagList{}, []string{}, &maxTimestamp, "latest")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("FindLatestSnapshot returned error: %v", err)
|
t.Fatalf("FindLatestSnapshot returned error: %v", err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue