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

include a root in car responses #355

Merged
merged 1 commit into from
Jul 13, 2023
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
2 changes: 1 addition & 1 deletion cmd/lassie/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ func defaultFetchRun(
carWriter = storage.NewDeferredCarWriterForPath(rootCid, outfile)
}

tempStore := storage.NewDeferredStorageCar(tempDir)
tempStore := storage.NewDeferredStorageCar(tempDir, rootCid)
carStore := storage.NewCachingTempStore(carWriter.BlockWriteOpener(), tempStore)
defer carStore.Close()

Expand Down
2 changes: 1 addition & 1 deletion pkg/server/http/ipfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func ipfsHandler(lassie *lassie.Lassie, cfg HttpServerConfig) func(http.Response
// the response writer. Once closed, no other content should be written.
bytesWritten := make(chan struct{}, 1)

tempStore := storage.NewDeferredStorageCar(cfg.TempDir)
tempStore := storage.NewDeferredStorageCar(cfg.TempDir, rootCid)
var carWriter storage.DeferredWriter
if includeDupes {
carWriter = storage.NewDuplicateAdderCarForStream(req.Context(), rootCid, path.String(), dagScope, tempStore, res)
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/cachingtempstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func TestDeferredCarWriterWritesCARv1(t *testing.T) {

var buf bytes.Buffer
cw := NewDeferredCarWriterForStream(testCid1, &buf)
ss := NewCachingTempStore(cw.BlockWriteOpener(), NewDeferredStorageCar(""))
ss := NewCachingTempStore(cw.BlockWriteOpener(), NewDeferredStorageCar("", testCid1))
t.Cleanup(func() { ss.Close() })

if tt.readBeforeWrite {
Expand Down
6 changes: 4 additions & 2 deletions pkg/storage/deferredstoragecar.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ var _ ReadableWritableStorage = (*DeferredStorageCar)(nil)
// in the case of an error).
type DeferredStorageCar struct {
tempDir string
root cid.Cid

lk sync.Mutex
closed bool
Expand All @@ -29,9 +30,10 @@ type DeferredStorageCar struct {
}

// NewDeferredStorageCar creates a new DeferredStorageCar.
func NewDeferredStorageCar(tempDir string) *DeferredStorageCar {
func NewDeferredStorageCar(tempDir string, root cid.Cid) *DeferredStorageCar {
return &DeferredStorageCar{
tempDir: tempDir,
root: root,
}
}

Expand Down Expand Up @@ -136,7 +138,7 @@ func (dcs *DeferredStorageCar) readWrite() (ReadableWritableStorage, error) {
if dcs.f, err = os.CreateTemp(dcs.tempDir, "lassie_carstorage"); err != nil {
return nil, err
}
rw, err := carstorage.NewReadableWritable(dcs.f, []cid.Cid{}, carv2.WriteAsCarV1(true))
rw, err := carstorage.NewReadableWritable(dcs.f, []cid.Cid{dcs.root}, carv2.WriteAsCarV1(true))
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/duplicateaddercar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestDuplicateAdderCar(t *testing.T) {
unixfsFileWithDupsBlocks := testutil.ToBlocks(t, lsys, unixfsFileWithDups.Root, selectorparse.CommonSelector_ExploreAllRecursively)
buf := new(bytes.Buffer)

store := storage.NewDeferredStorageCar("")
store := storage.NewDeferredStorageCar("", unixfsFileWithDups.Root)
ctx := context.Background()
carWriter := storage.NewDuplicateAdderCarForStream(ctx, unixfsFileWithDups.Root, "", types.DagScopeAll, store, buf)
cachingTempStore := storage.NewCachingTempStore(carWriter.BlockWriteOpener(), store)
Expand Down
6 changes: 3 additions & 3 deletions pkg/storage/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ func TestTempCarStorage(t *testing.T) {
return nil
}, nil
}
cw = NewCachingTempStore(bwo, NewDeferredStorageCar(tempDir))
cw = NewCachingTempStore(bwo, NewDeferredStorageCar(tempDir, testCid1))
} else {
cw = NewDeferredStorageCar(tempDir)
cw = NewDeferredStorageCar(tempDir, testCid1)
}

ents, err := os.ReadDir(tempDir)
Expand Down Expand Up @@ -154,7 +154,7 @@ func TestPreloadStore(t *testing.T) {
return nil
}, nil
}
mainStore := NewCachingTempStore(bwo, NewDeferredStorageCar(t.TempDir()))
mainStore := NewCachingTempStore(bwo, NewDeferredStorageCar(t.TempDir(), td[0].cid))
t.Cleanup(func() {
require.NoError(t, mainStore.Close())
})
Expand Down