@@ -224,6 +224,9 @@ func NewC1ZFile(ctx context.Context, outputFilePath string, opts ...C1ZOption) (
224224 for _ , opt := range opts {
225225 opt (options )
226226 }
227+ if options .encoderConcurrency < 0 {
228+ return nil , fmt .Errorf ("encoder concurrency must be greater than 0" )
229+ }
227230
228231 dbFilePath , _ , err := decompressC1z (outputFilePath , options .tmpDir , options .decoderOptions ... )
229232 if err != nil {
@@ -242,17 +245,14 @@ func NewC1ZFile(ctx context.Context, outputFilePath string, opts ...C1ZOption) (
242245 if options .readOnly {
243246 c1fopts = append (c1fopts , WithC1FReadOnly (true ))
244247 }
245- if options .encoderConcurrency < 0 {
246- return nil , fmt .Errorf ("encoder concurrency must be greater than 0" )
247- }
248248 c1fopts = append (c1fopts , WithC1FEncoderConcurrency (options .encoderConcurrency ))
249249 if options .syncLimit > 0 {
250250 c1fopts = append (c1fopts , WithC1FSyncCountLimit (options .syncLimit ))
251251 }
252252
253253 c1File , err := NewC1File (ctx , dbFilePath , c1fopts ... )
254254 if err != nil {
255- return nil , err
255+ return nil , cleanupDbDir ( dbFilePath , err )
256256 }
257257
258258 c1File .outputFilePath = outputFilePath
@@ -261,7 +261,7 @@ func NewC1ZFile(ctx context.Context, outputFilePath string, opts ...C1ZOption) (
261261}
262262
263263func cleanupDbDir (dbFilePath string , err error ) error {
264- cleanupErr := os .RemoveAll (filepath .Dir (dbFilePath ))
264+ cleanupErr := os .RemoveAll (filepath .Dir (dbFilePath )) //nolint:gosec // G703 -- dbFilePath is a caller-provided path by design.
265265 if cleanupErr != nil {
266266 err = errors .Join (err , cleanupErr )
267267 }
0 commit comments