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

Only copy live objects #82

Merged
merged 1 commit into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions internal/db/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func CopyAllObjects(ctx context.Context, tx pgx.Tx, source int64, target int64)
SELECT $1, start_version, stop_version, path, hash, mode, size, packed
FROM dl.objects
WHERE project = $2
AND stop_version IS NULL
`, target, source)
if err != nil {
return fmt.Errorf("copy project, source %v, target %v: %w", source, target, err)
Expand Down
4 changes: 4 additions & 0 deletions test/fs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ func TestNewProjectWithTemplate(t *testing.T) {
"/b": {content: "b v3"},
"/c": {content: "c v3"},
})

// Copied projects should only contain live objects
assert.Equal(t, 4, countObjectsByProject(tc, 1))
assert.Equal(t, 2, countObjectsByProject(tc, 2))
}

func TestGetEmpty(t *testing.T) {
Expand Down
14 changes: 14 additions & 0 deletions test/shared_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,20 @@ func countContents(tc util.TestCtx) int {
return count
}

func countObjectsByProject(tc util.TestCtx, project int64) int {
conn := tc.Connect()

var count int
err := conn.QueryRow(tc.Context(), `
SELECT count(*)
FROM dl.objects
WHERE project = $1
`, project).Scan(&count)
require.NoError(tc.T(), err, "count objects")

return count
}

func writeObjectFull(tc util.TestCtx, project int64, start int64, stop *int64, path, content string, mode fs.FileMode) {
conn := tc.Connect()

Expand Down
Loading