Skip to content

Commit

Permalink
Only copy live objects
Browse files Browse the repository at this point in the history
  • Loading branch information
angelini committed Apr 10, 2024
1 parent 07929f5 commit 4999ce9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
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

0 comments on commit 4999ce9

Please sign in to comment.