@@ -296,6 +296,10 @@ func (bb *BlocksBackend) Head(ctx context.Context, path path.ImmutablePath) (Con
296296var emptyRoot = []cid.Cid {cid .MustParse ("bafkqaaa" )}
297297
298298func (bb * BlocksBackend ) GetCAR (ctx context.Context , p path.ImmutablePath , params CarParams ) (ContentPathMetadata , io.ReadCloser , error ) {
299+ if params .SkipRawBlocks .Bool () && p .RootCid ().Prefix ().Codec == cid .Raw {
300+
301+ }
302+
299303 pathMetadata , err := bb .ResolvePath (ctx , p )
300304 if err != nil {
301305 rootCid , err := cid .Decode (strings .Split (p .String (), "/" )[2 ])
@@ -312,8 +316,9 @@ func (bb *BlocksBackend) GetCAR(ctx context.Context, p path.ImmutablePath, param
312316 blockGetter := merkledag .NewDAGService (bb .blockService ).Session (ctx )
313317
314318 blockGetter = & nodeGetterToCarExporer {
315- ng : blockGetter ,
316- cw : cw ,
319+ ng : blockGetter ,
320+ cw : cw ,
321+ skipRawBlocks : params .SkipRawBlocks .Bool (),
317322 }
318323
319324 // Setup the UnixFS resolver.
@@ -352,8 +357,9 @@ func (bb *BlocksBackend) GetCAR(ctx context.Context, p path.ImmutablePath, param
352357 blockGetter := merkledag .NewDAGService (bb .blockService ).Session (ctx )
353358
354359 blockGetter = & nodeGetterToCarExporer {
355- ng : blockGetter ,
356- cw : cw ,
360+ ng : blockGetter ,
361+ cw : cw ,
362+ skipRawBlocks : params .SkipRawBlocks .Bool (),
357363 }
358364
359365 // Setup the UnixFS resolver.
@@ -732,8 +738,9 @@ func (bb *BlocksBackend) resolvePath(ctx context.Context, p path.Path) (path.Imm
732738}
733739
734740type nodeGetterToCarExporer struct {
735- ng format.NodeGetter
736- cw storage.WritableCar
741+ ng format.NodeGetter
742+ cw storage.WritableCar
743+ skipRawBlocks bool
737744}
738745
739746func (n * nodeGetterToCarExporer ) Get (ctx context.Context , c cid.Cid ) (format.Node , error ) {
@@ -774,6 +781,19 @@ func (n *nodeGetterToCarExporer) GetMany(ctx context.Context, cids []cid.Cid) <-
774781}
775782
776783func (n * nodeGetterToCarExporer ) trySendBlock (ctx context.Context , block blocks.Block ) error {
784+ // FIXME(@Jorropo): this is very inneficient, we fetch all blocks even if we don't send them.
785+ // I've tried doing so using the ipld stack however the problem is that filtering on the
786+ // selector or traversal callback does not work because the unixfs reifier is ran before,
787+ // so trying to filter raw links do nothing because go-unixfsnode removed them already,
788+ // so we need to filter in a callback from unixfsnode but the reifier does not know a about
789+ // [traversal.SkipMe] making it a lost cause. I've looked into updating unixfsnode but this
790+ // much more work because there are no easy way to pass options or understand what the side
791+ // effects of this would be.
792+ // Abstractions everywhere yet a simple small behaviour change require rethinking everything :'(.
793+ // Will fix with boxo/unixfs.
794+ if n .skipRawBlocks && block .Cid ().Prefix ().Codec == cid .Raw {
795+ return nil
796+ }
777797 return n .cw .Put (ctx , block .Cid ().KeyString (), block .RawData ())
778798}
779799
0 commit comments