Skip to content

Commit

Permalink
Merge pull request #4724 from MichaelEischer/disable-old-index
Browse files Browse the repository at this point in the history
Deprecated legacy index format
  • Loading branch information
MichaelEischer committed Mar 28, 2024
2 parents 4f4979f + 69ca12d commit 8876e30
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 4 deletions.
13 changes: 13 additions & 0 deletions changelog/unreleased/issue-4602
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Change: Deprecate legacy index format

Support for the legacy index format used by restic before version 0.2.0 has
been depreacted and will be removed in the next minor restic version. You can
use `restic repair index` to update the index to the current format.

It is possible to temporarily reenable support for the legacy index format by
setting the environment variable
`RESTIC_FEATURES=deprecate-legacy-index=false`. Note that this feature flag
will be removed in the next minor restic version.

https://github.com/restic/restic/issues/4602
https://github.com/restic/restic/pull/4724
12 changes: 10 additions & 2 deletions cmd/restic/cmd_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,12 +231,17 @@ func runCheck(ctx context.Context, opts CheckOptions, gopts GlobalOptions, args

errorsFound := false
suggestIndexRebuild := false
suggestLegacyIndexRebuild := false
mixedFound := false
for _, hint := range hints {
switch hint.(type) {
case *checker.ErrDuplicatePacks, *checker.ErrOldIndexFormat:
case *checker.ErrDuplicatePacks:
Printf("%v\n", hint)
suggestIndexRebuild = true
case *checker.ErrOldIndexFormat:
Warnf("error: %v\n", hint)
suggestLegacyIndexRebuild = true
errorsFound = true
case *checker.ErrMixedPack:
Printf("%v\n", hint)
mixedFound = true
Expand All @@ -247,7 +252,10 @@ func runCheck(ctx context.Context, opts CheckOptions, gopts GlobalOptions, args
}

if suggestIndexRebuild {
Printf("Duplicate packs/old indexes are non-critical, you can run `restic repair index' to correct this.\n")
Printf("Duplicate packs are non-critical, you can run `restic repair index' to correct this.\n")
}
if suggestLegacyIndexRebuild {
Warnf("Found indexes using the legacy format, you must run `restic repair index' to correct this.\n")
}
if mixedFound {
Printf("Mixed packs with tree and data blobs are non-critical, you can run `restic prune` to correct this.\n")
Expand Down
Binary file modified cmd/restic/testdata/repo-restore-permissions-test.tar.gz
Binary file not shown.
6 changes: 4 additions & 2 deletions internal/feature/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ var Flag = New()

// flag names are written in kebab-case
const (
ExampleFeature FlagName = "example-feature"
ExampleFeature FlagName = "example-feature"
DeprecateLegacyIndex FlagName = "deprecate-legacy-index"
)

func init() {
Flag.SetFlags(map[FlagName]FlagDesc{
ExampleFeature: {Type: Alpha, Description: "just for testing"},
ExampleFeature: {Type: Alpha, Description: "just for testing"},
DeprecateLegacyIndex: {Type: Beta, Description: "disable support for index format used by restic 0.1.0. Use `restic repair index` to update the index if necessary."},
})
}
7 changes: 7 additions & 0 deletions internal/index/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ package index
import (
"context"
"encoding/json"
"fmt"
"io"
"sync"
"time"

"github.com/restic/restic/internal/crypto"
"github.com/restic/restic/internal/errors"
"github.com/restic/restic/internal/feature"
"github.com/restic/restic/internal/restic"

"github.com/restic/restic/internal/debug"
Expand Down Expand Up @@ -515,8 +517,13 @@ func DecodeIndex(buf []byte, id restic.ID) (idx *Index, oldFormat bool, err erro
debug.Log("Error %v", err)

if isErrOldIndex(err) {
if feature.Flag.Enabled(feature.DeprecateLegacyIndex) {
return nil, false, fmt.Errorf("index seems to use the legacy format. update it using `restic repair index`")
}

debug.Log("index is probably old format, trying that")
idx, err = decodeOldIndex(buf)
idx.ids = append(idx.ids, id)
return idx, err == nil, err
}

Expand Down
3 changes: 3 additions & 0 deletions internal/index/index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"sync"
"testing"

"github.com/restic/restic/internal/feature"
"github.com/restic/restic/internal/index"
"github.com/restic/restic/internal/restic"
rtest "github.com/restic/restic/internal/test"
Expand Down Expand Up @@ -427,6 +428,8 @@ func BenchmarkEncodeIndex(b *testing.B) {
}

func TestIndexUnserializeOld(t *testing.T) {
defer feature.TestSetFlag(t, feature.Flag, feature.DeprecateLegacyIndex, false)()

idx, oldFormat, err := index.DecodeIndex(docOldExample, restic.NewRandomID())
rtest.OK(t, err)
rtest.Assert(t, oldFormat, "old index format recognized as new format")
Expand Down

0 comments on commit 8876e30

Please sign in to comment.