@@ -1123,17 +1123,31 @@ func (api *CarBackend) GetCAR(ctx context.Context, p path.ImmutablePath, params
1123
1123
}
1124
1124
l := getLinksystem (teeBlock )
1125
1125
1126
+ var isNotFound bool
1127
+
1126
1128
// First resolve the path since we always need to.
1127
1129
md , terminalBlk , err := resolvePathWithRootsAndBlock (ctx , p , l )
1128
1130
if err != nil {
1129
- return err
1131
+ if isErrNotFound (err ) {
1132
+ isNotFound = true
1133
+ } else {
1134
+ return err
1135
+ }
1130
1136
}
1137
+
1131
1138
if len (md .LastSegmentRemainder ) > 0 {
1132
1139
return nil
1133
1140
}
1134
1141
1135
1142
if cw == nil {
1136
- cw , err = storage .NewWritable (w , []cid.Cid {md .LastSegment .RootCid ()}, carv2 .WriteAsCarV1 (true ), carv2 .AllowDuplicatePuts (params .Duplicates .Bool ()))
1143
+ var roots []cid.Cid
1144
+ if isNotFound {
1145
+ roots = emptyRoot
1146
+ } else {
1147
+ roots = []cid.Cid {md .LastSegment .RootCid ()}
1148
+ }
1149
+
1150
+ cw , err = storage .NewWritable (w , roots , carv2 .WriteAsCarV1 (true ), carv2 .AllowDuplicatePuts (params .Duplicates .Bool ()))
1137
1151
if err != nil {
1138
1152
// io.PipeWriter.CloseWithError always returns nil.
1139
1153
_ = w .CloseWithError (err )
@@ -1149,12 +1163,14 @@ func (api *CarBackend) GetCAR(ctx context.Context, p path.ImmutablePath, params
1149
1163
blockBuffer = nil
1150
1164
}
1151
1165
1152
- params .Duplicates = DuplicateBlocksIncluded
1153
- err = walkGatewaySimpleSelector (ctx , terminalBlk .Cid (), terminalBlk , []string {}, params , l )
1154
- // err = walkGatewaySimpleSelector2(ctx, terminalBlk, params.Scope, params.Range, l)
1155
- if err != nil {
1156
- return err
1166
+ if ! isNotFound {
1167
+ params .Duplicates = DuplicateBlocksIncluded
1168
+ err = walkGatewaySimpleSelector (ctx , terminalBlk .Cid (), terminalBlk , []string {}, params , l )
1169
+ if err != nil {
1170
+ return err
1171
+ }
1157
1172
}
1173
+
1158
1174
return nil
1159
1175
})
1160
1176
0 commit comments