Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix untar test #241

Merged
merged 1 commit into from
Jul 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions cmd/desync/untar_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build !windows
// +build !windows

package main
Expand Down Expand Up @@ -39,23 +40,21 @@ func TestUntarCommandIndex(t *testing.T) {
require.NoError(t, err)
}

// Check that we repair broken chunks in chache
// Check that we repair broken chunks in cache
func TestUntarCommandRepair(t *testing.T) {
// Create an output dir to extract into
out, err := ioutil.TempDir("", "")
require.NoError(t, err)
defer os.RemoveAll(out)
out := t.TempDir()

// Create cache with invalid chunk
cache, err := ioutil.TempDir("", "brokencache")
require.NoError(t, err)
defer os.RemoveAll(cache)
// Create cache with invalid chunk by reading a chunk from another store, and writing it to the cache with the wrong id
cache := t.TempDir()

chunkId := "0589328ff916d08f5fe59a9aa0731571448e91341f37ca5484a85b9f0af14de3"
badChunkHash := "c672b8d1ef56ed28ab87c3622c5114069bdd3ad7b8f9737498d0c01ecef0967a"
err = os.Mkdir(path.Join(cache, chunkId[:4]), os.ModePerm)
badChunkHash := "0b2a199263ffb2600b6f8be2e03b7439ffb0ad05a00b867f427a716e3e386c2d"
err := os.Mkdir(path.Join(cache, chunkId[:4]), os.ModePerm)
require.NoError(t, err)
b, err := os.ReadFile(path.Join("testdata/blob1.store", badChunkHash[:4], badChunkHash+".cacnk"))
require.NoError(t, err)
err = ioutil.WriteFile(path.Join(cache, chunkId[:4], chunkId+".cacnk"), []byte("42"), os.ModePerm)
err = os.WriteFile(path.Join(cache, chunkId[:4], chunkId+".cacnk"), b, os.ModePerm)
require.NoError(t, err)

// Run "untar" with "--repair=false" -> get error
Expand Down