@@ -296,6 +296,10 @@ func (bb *BlocksBackend) Head(ctx context.Context, path path.ImmutablePath) (Con
296
296
var emptyRoot = []cid.Cid {cid .MustParse ("bafkqaaa" )}
297
297
298
298
func (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
+
299
303
pathMetadata , err := bb .ResolvePath (ctx , p )
300
304
if err != nil {
301
305
rootCid , err := cid .Decode (strings .Split (p .String (), "/" )[2 ])
@@ -312,8 +316,9 @@ func (bb *BlocksBackend) GetCAR(ctx context.Context, p path.ImmutablePath, param
312
316
blockGetter := merkledag .NewDAGService (bb .blockService ).Session (ctx )
313
317
314
318
blockGetter = & nodeGetterToCarExporer {
315
- ng : blockGetter ,
316
- cw : cw ,
319
+ ng : blockGetter ,
320
+ cw : cw ,
321
+ skipRawBlocks : params .SkipRawBlocks .Bool (),
317
322
}
318
323
319
324
// Setup the UnixFS resolver.
@@ -352,8 +357,9 @@ func (bb *BlocksBackend) GetCAR(ctx context.Context, p path.ImmutablePath, param
352
357
blockGetter := merkledag .NewDAGService (bb .blockService ).Session (ctx )
353
358
354
359
blockGetter = & nodeGetterToCarExporer {
355
- ng : blockGetter ,
356
- cw : cw ,
360
+ ng : blockGetter ,
361
+ cw : cw ,
362
+ skipRawBlocks : params .SkipRawBlocks .Bool (),
357
363
}
358
364
359
365
// Setup the UnixFS resolver.
@@ -732,8 +738,9 @@ func (bb *BlocksBackend) resolvePath(ctx context.Context, p path.Path) (path.Imm
732
738
}
733
739
734
740
type nodeGetterToCarExporer struct {
735
- ng format.NodeGetter
736
- cw storage.WritableCar
741
+ ng format.NodeGetter
742
+ cw storage.WritableCar
743
+ skipRawBlocks bool
737
744
}
738
745
739
746
func (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) <-
774
781
}
775
782
776
783
func (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
+ }
777
797
return n .cw .Put (ctx , block .Cid ().KeyString (), block .RawData ())
778
798
}
779
799
0 commit comments