2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-26 06:46:34 +00:00

FindLatestSnapshot: Use absolute paths

This commit is contained in:
Alexander Neumann 2018-03-03 18:02:47 +01:00
parent fa4f438bc1
commit baebf45e2e

View File

@ -4,6 +4,7 @@ import (
"context"
"fmt"
"os"
"path/filepath"
"time"
"github.com/restic/restic/internal/errors"
@ -14,13 +15,25 @@ var ErrNoSnapshotFound = errors.New("no snapshot found")
// FindLatestSnapshot finds latest snapshot with optional target/directory, tags and hostname filters.
func FindLatestSnapshot(ctx context.Context, repo Repository, targets []string, tagLists []TagList, hostname string) (ID, error) {
var err error
absTargets := make([]string, 0, len(targets))
for _, target := range targets {
if !filepath.IsAbs(target) {
target, err = filepath.Abs(target)
if err != nil {
return ID{}, errors.Wrap(err, "Abs")
}
}
absTargets = append(absTargets, target)
}
var (
latest time.Time
latestID ID
found bool
)
err := repo.List(ctx, SnapshotFile, func(snapshotID ID, size int64) error {
err = repo.List(ctx, SnapshotFile, func(snapshotID ID, size int64) error {
snapshot, err := LoadSnapshot(ctx, repo, snapshotID)
if err != nil {
return errors.Errorf("Error loading snapshot %v: %v", snapshotID.Str(), err)
@ -33,7 +46,7 @@ func FindLatestSnapshot(ctx context.Context, repo Repository, targets []string,
return nil
}
if !snapshot.HasPaths(targets) {
if !snapshot.HasPaths(absTargets) {
return nil
}