diff --git a/internal/repository/repository.go b/internal/repository/repository.go index f26226ffd..33eab8cb0 100644 --- a/internal/repository/repository.go +++ b/internal/repository/repository.go @@ -163,12 +163,6 @@ func (r *Repository) SetDryRun() { r.be = dryrun.New(r.be) } -// PrefixLength returns the number of bytes required so that all prefixes of -// all IDs of type t are unique. -func (r *Repository) PrefixLength(ctx context.Context, t restic.FileType) (int, error) { - return restic.PrefixLength(ctx, r.be, t) -} - // LoadUnpacked loads and decrypts the file with the given type and ID, using // the supplied buffer (which must be empty). If the buffer is nil, a new // buffer will be allocated and returned. diff --git a/internal/restic/backend_find.go b/internal/restic/backend_find.go index 4be2f523f..8ce57dd1d 100644 --- a/internal/restic/backend_find.go +++ b/internal/restic/backend_find.go @@ -61,42 +61,3 @@ func Find(ctx context.Context, be Lister, t FileType, prefix string) (string, er return "", &NoIDByPrefixError{prefix} } - -const minPrefixLength = 8 - -// PrefixLength returns the number of bytes required so that all prefixes of -// all names of type t are unique. -func PrefixLength(ctx context.Context, be Lister, t FileType) (int, error) { - // load all IDs of the given type - list := make([]string, 0, 100) - - ctx, cancel := context.WithCancel(ctx) - defer cancel() - - err := be.List(ctx, t, func(fi FileInfo) error { - list = append(list, fi.Name) - return nil - }) - - if err != nil { - return 0, err - } - - // select prefixes of length l, test if the last one is the same as the current one - var id ID -outer: - for l := minPrefixLength; l < len(id); l++ { - var last string - - for _, name := range list { - if last == name[:l] { - continue outer - } - last = name[:l] - } - - return l, nil - } - - return len(id), nil -} diff --git a/internal/restic/backend_find_test.go b/internal/restic/backend_find_test.go index 52eb38ef3..bd1e6f7e6 100644 --- a/internal/restic/backend_find_test.go +++ b/internal/restic/backend_find_test.go @@ -75,44 +75,3 @@ func TestFind(t *testing.T) { t.Errorf("Find should not return a match on error.") } } - -func TestPrefixLength(t *testing.T) { - list := samples - - m := mockBackend{} - m.list = func(ctx context.Context, t FileType, fn func(FileInfo) error) error { - for _, id := range list { - err := fn(FileInfo{Name: id.String()}) - if err != nil { - return err - } - } - return nil - } - - l, err := PrefixLength(context.TODO(), m, SnapshotFile) - if err != nil { - t.Error(err) - } - if l != 19 { - t.Errorf("wrong prefix length returned, want %d, got %d", 19, l) - } - - list = samples[:3] - l, err = PrefixLength(context.TODO(), m, SnapshotFile) - if err != nil { - t.Error(err) - } - if l != 19 { - t.Errorf("wrong prefix length returned, want %d, got %d", 19, l) - } - - list = samples[3:] - l, err = PrefixLength(context.TODO(), m, SnapshotFile) - if err != nil { - t.Error(err) - } - if l != 8 { - t.Errorf("wrong prefix length returned, want %d, got %d", 8, l) - } -}