diff --git a/cmd/restic/cmd_init_integration_test.go b/cmd/restic/cmd_init_integration_test.go index d2e96a613..2bfd9c7fb 100644 --- a/cmd/restic/cmd_init_integration_test.go +++ b/cmd/restic/cmd_init_integration_test.go @@ -25,6 +25,7 @@ func testRunInit(t testing.TB, gopts global.Options) { // create temporary junk files to verify that restic does not trip over them for _, path := range []string{"index", "snapshots", "keys", "locks", filepath.Join("data", "00")} { + rtest.OK(t, os.MkdirAll(filepath.Join(gopts.Repo, path), 0700)) rtest.OK(t, os.WriteFile(filepath.Join(gopts.Repo, path, "tmp12345"), []byte("junk file"), 0o600)) } } diff --git a/cmd/restic/integration_helpers_test.go b/cmd/restic/integration_helpers_test.go index 614fa916f..54ad884d6 100644 --- a/cmd/restic/integration_helpers_test.go +++ b/cmd/restic/integration_helpers_test.go @@ -14,6 +14,7 @@ import ( "github.com/restic/restic/internal/backend" "github.com/restic/restic/internal/backend/all" + "github.com/restic/restic/internal/backend/layout" "github.com/restic/restic/internal/backend/retry" "github.com/restic/restic/internal/data" "github.com/restic/restic/internal/errors" @@ -192,6 +193,7 @@ func withTestEnvironment(t testing.TB) (env *testEnvironment, cleanup func()) { repository.TestUseLowSecurityKDFParameters(t) restic.TestDisableCheckPolynomial(t) retry.TestFastRetries(t) + layout.TestDisablePackSubdirs(t) tempdir, err := os.MkdirTemp(rtest.TestTempDir, "restic-test-") rtest.OK(t, err) diff --git a/internal/backend/layout/layout_default.go b/internal/backend/layout/layout_default.go index d2c4634d3..6566da5a7 100644 --- a/internal/backend/layout/layout_default.go +++ b/internal/backend/layout/layout_default.go @@ -6,6 +6,10 @@ import ( "github.com/restic/restic/internal/backend" ) +// disablePackSubdirs is used to disable the creation of pack subdirectories. +// Only used for testing. +var disablePackSubdirs = false + // DefaultLayout implements the default layout for local and sftp backends, as // described in the Design document. The `data` directory has one level of // subdirs, two characters each (taken from the first two characters of the @@ -66,10 +70,12 @@ func (l *DefaultLayout) Paths() (dirs []string) { dirs = append(dirs, l.join(l.path, p)) } - // also add subdirs - for i := 0; i < 256; i++ { - subdir := hex.EncodeToString([]byte{byte(i)}) - dirs = append(dirs, l.join(l.path, defaultLayoutPaths[backend.PackFile], subdir)) + if !disablePackSubdirs { + // also add subdirs + for i := 0; i < 256; i++ { + subdir := hex.EncodeToString([]byte{byte(i)}) + dirs = append(dirs, l.join(l.path, defaultLayoutPaths[backend.PackFile], subdir)) + } } return dirs diff --git a/internal/backend/layout/testing.go b/internal/backend/layout/testing.go new file mode 100644 index 000000000..c69932776 --- /dev/null +++ b/internal/backend/layout/testing.go @@ -0,0 +1,9 @@ +package layout + +import ( + "testing" +) + +func TestDisablePackSubdirs(t testing.TB) { + disablePackSubdirs = true +}