mirror of
https://github.com/octoleo/restic.git
synced 2024-12-22 10:58:55 +00:00
Merge pull request #3943 from MichaelEischer/find-match-only-valid-ids
ignore filenames which are not IDs when expanding a prefix
This commit is contained in:
commit
e89fc2a29d
9
changelog/unreleased/pull-3943
Normal file
9
changelog/unreleased/pull-3943
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
Enhancement: Ignore additional files in repository
|
||||||
|
|
||||||
|
Some commands like `find` and `restore` could become confused by additional
|
||||||
|
files in the repository. This could cause restic to fail with an `multiple IDs
|
||||||
|
with prefix "12345678" found` error. These commands now ignore additional
|
||||||
|
files.
|
||||||
|
|
||||||
|
https://github.com/restic/restic/pull/3943
|
||||||
|
https://forum.restic.net/t/which-protocol-should-i-choose-for-remote-linux-backups/5446/17
|
@ -3,6 +3,8 @@ package restic
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/restic/restic/internal/debug"
|
||||||
)
|
)
|
||||||
|
|
||||||
// A MultipleIDMatchesError is returned by Find() when multiple IDs with a
|
// A MultipleIDMatchesError is returned by Find() when multiple IDs with a
|
||||||
@ -31,6 +33,13 @@ func Find(ctx context.Context, be Lister, t FileType, prefix string) (string, er
|
|||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
err := be.List(ctx, t, func(fi FileInfo) error {
|
err := be.List(ctx, t, func(fi FileInfo) error {
|
||||||
|
// ignore filename which are not an id
|
||||||
|
_, err := ParseID(fi.Name)
|
||||||
|
if err != nil {
|
||||||
|
debug.Log("unable to parse %v as an ID", fi.Name)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
if len(fi.Name) >= len(prefix) && prefix == fi.Name[:len(prefix)] {
|
if len(fi.Name) >= len(prefix) && prefix == fi.Name[:len(prefix)] {
|
||||||
if match == "" {
|
if match == "" {
|
||||||
match = fi.Name
|
match = fi.Name
|
||||||
|
Loading…
Reference in New Issue
Block a user