Skip to content

Commit 84006f2

Browse files
authored
NewExternalC1FileReader: Clean up temp files if NewC1File errors. (#702)
Also open the external c1z file in read-only mode. We never modify it, and we never should.
1 parent 51db721 commit 84006f2

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

pkg/dotc1z/dotc1z.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ import (
77
"io"
88

99
"go.opentelemetry.io/otel"
10+
"go.uber.org/zap"
1011

1112
"github.com/conductorone/baton-sdk/pkg/connectorstore"
13+
"github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/ctxzap"
1214
)
1315

1416
var tracer = otel.Tracer("baton-sdk/pkg.dotc1z")
@@ -54,6 +56,16 @@ func NewExternalC1FileReader(ctx context.Context, tmpDir string, externalResourc
5456
if err != nil {
5557
return nil, fmt.Errorf("error loading external resource c1z file: %w", err)
5658
}
59+
l := ctxzap.Extract(ctx)
60+
l.Debug("new-external-c1z-file: decompressed c1z",
61+
zap.String("db_file_path", dbFilePath),
62+
zap.String("external_resource_c1z_path", externalResourceC1ZPath),
63+
)
5764

58-
return NewC1File(ctx, dbFilePath)
65+
c1File, err := NewC1File(ctx, dbFilePath, WithC1FReadOnly(true))
66+
if err != nil {
67+
return nil, cleanupDbDir(dbFilePath, err)
68+
}
69+
70+
return c1File, nil
5971
}

0 commit comments

Comments
 (0)