@@ -18,6 +18,7 @@ import (
18
18
"github.com/turbot/tailpipe-plugin-sdk/collection_state"
19
19
"github.com/turbot/tailpipe-plugin-sdk/context_values"
20
20
"github.com/turbot/tailpipe-plugin-sdk/events"
21
+ "github.com/turbot/tailpipe-plugin-sdk/filepaths"
21
22
"github.com/turbot/tailpipe-plugin-sdk/helpers"
22
23
"github.com/turbot/tailpipe-plugin-sdk/parse"
23
24
"github.com/turbot/tailpipe-plugin-sdk/rate_limiter"
@@ -61,7 +62,7 @@ type ArtifactSourceImpl[S artifact_source_config.ArtifactSourceConfig, T parse.C
61
62
62
63
// temporary directory for storing downloaded artifacts - this is initialised in the Init function
63
64
// to be a subdirectory of the collection directory
64
- TempDir string
65
+ TempArtifactDir string
65
66
66
67
// shadow the row_source.RowSourceImpl Source property, but using ArtifactSource interface
67
68
Source ArtifactSource
@@ -95,8 +96,12 @@ func (a *ArtifactSourceImpl[S, T]) Init(ctx context.Context, params *row_source.
95
96
a .NewCollectionStateFunc = collection_state .NewArtifactCollectionStateImpl
96
97
}
97
98
98
- // set the temp directory
99
- a .TempDir = filepath .Join (params .CollectionTempDir , "artifacts" )
99
+ // set the artifact directory
100
+ artifactDir , err := filepaths .EnsureArtifactPath (params .CollectionTempDir )
101
+ if err != nil {
102
+ return err
103
+ }
104
+ a .TempArtifactDir = artifactDir
100
105
101
106
// call base to apply options and parse config
102
107
if err := a .RowSourceImpl .Init (ctx , params , opts ... ); err != nil {
@@ -215,6 +220,11 @@ func (a *ArtifactSourceImpl[S, T]) OnArtifactDiscovered(ctx context.Context, inf
215
220
a .artifactDownloadLimiter .Release ()
216
221
slog .Debug ("ArtifactDiscovered - rate limiter released" , "artifact" , info .Name )
217
222
}()
223
+
224
+ // as this is called from the file walking code, rather than as a result of an event,
225
+ // we need to check for pausing here to avoid downloading artifacts when paused
226
+ a .BlockWhilePaused (ctx )
227
+
218
228
// cast the source to an ArtifactSource and download the artifact
219
229
err = a .Source .DownloadArtifact (ctx , info )
220
230
if err != nil {
@@ -254,15 +264,6 @@ func (a *ArtifactSourceImpl[S, T]) OnArtifactDownloaded(ctx context.Context, inf
254
264
return fmt .Errorf ("error updating collection state: %w" , err )
255
265
}
256
266
257
- // TODO verify if this condition can still occur
258
- // we have a race condition - if the processArtifact completes before we have time to handle the ArtifactDownloadedEvent
259
- // ArtifactSourceImpl.Collect may return before this function is complete
260
- // this may lead to sending a completion event before the artifact has been processed
261
- // we need to ensure the wait group is not closed before we leave this function
262
- //so increment the wait group again and
263
- //a.artifactExtractWg.Add(1)
264
- //defer a.artifactExtractWg.Done()
265
-
266
267
// if we DO NOT have a null loader, start the go routine to process the artifact
267
268
// (if we have a null loader, we must have a ArtifactConversionCollector which will do the processing)
268
269
if ! nullLoader {
0 commit comments