archiver: move deviceID handling behind feature flag

This commit is contained in:
Michael Eischer 2024-03-09 17:44:48 +01:00
parent 2ba21fe72b
commit a26d6ffa72
3 changed files with 13 additions and 5 deletions

View File

@ -12,6 +12,7 @@ import (
"github.com/restic/restic/internal/debug" "github.com/restic/restic/internal/debug"
"github.com/restic/restic/internal/errors" "github.com/restic/restic/internal/errors"
"github.com/restic/restic/internal/feature"
"github.com/restic/restic/internal/fs" "github.com/restic/restic/internal/fs"
"github.com/restic/restic/internal/restic" "github.com/restic/restic/internal/restic"
"golang.org/x/sync/errgroup" "golang.org/x/sync/errgroup"
@ -188,11 +189,13 @@ func (arch *Archiver) nodeFromFileInfo(snPath, filename string, fi os.FileInfo)
if !arch.WithAtime { if !arch.WithAtime {
node.AccessTime = node.ModTime node.AccessTime = node.ModTime
} }
if node.Links == 1 || node.Type == "dir" { if feature.Flag.Enabled(feature.DeviceIDForHardlinks) {
// the DeviceID is only necessary for hardlinked files if node.Links == 1 || node.Type == "dir" {
// when using subvolumes or snapshots their deviceIDs tend to change which causes // the DeviceID is only necessary for hardlinked files
// restic to upload new tree blobs // when using subvolumes or snapshots their deviceIDs tend to change which causes
node.DeviceID = 0 // restic to upload new tree blobs
node.DeviceID = 0
}
} }
// overwrite name to match that within the snapshot // overwrite name to match that within the snapshot
node.Name = path.Base(snPath) node.Name = path.Base(snPath)

View File

@ -19,6 +19,7 @@ import (
"github.com/restic/restic/internal/backend/mem" "github.com/restic/restic/internal/backend/mem"
"github.com/restic/restic/internal/checker" "github.com/restic/restic/internal/checker"
"github.com/restic/restic/internal/errors" "github.com/restic/restic/internal/errors"
"github.com/restic/restic/internal/feature"
"github.com/restic/restic/internal/fs" "github.com/restic/restic/internal/fs"
"github.com/restic/restic/internal/repository" "github.com/restic/restic/internal/repository"
"github.com/restic/restic/internal/restic" "github.com/restic/restic/internal/restic"
@ -2125,6 +2126,8 @@ const (
) )
func TestMetadataChanged(t *testing.T) { func TestMetadataChanged(t *testing.T) {
defer feature.TestSetFlag(t, feature.Flag, feature.DeviceIDForHardlinks, true)()
files := TestDir{ files := TestDir{
"testfile": TestFile{ "testfile": TestFile{
Content: "foo bar test file", Content: "foo bar test file",

View File

@ -7,11 +7,13 @@ var Flag = New()
const ( const (
ExampleFeature FlagName = "example-feature" ExampleFeature FlagName = "example-feature"
DeprecateLegacyIndex FlagName = "deprecate-legacy-index" DeprecateLegacyIndex FlagName = "deprecate-legacy-index"
DeviceIDForHardlinks FlagName = "device-id-for-hardlinks"
) )
func init() { func init() {
Flag.SetFlags(map[FlagName]FlagDesc{ 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."}, 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."},
DeviceIDForHardlinks: {Type: Alpha, Description: "store deviceID only for hardlinks to reduce metadata changes for example when using btrfs subvolumes. Will be removed in a future restic version after repository format 3 is available"},
}) })
} }