@@ -53,6 +53,7 @@ func sftpInputSpec() *service.ConfigSpec {
53
53
This input adds the following metadata fields to each message:
54
54
55
55
- sftp_path
56
+ - sftp_mod_time
56
57
57
58
You can access these metadata fields using xref:configuration:interpolation.adoc#bloblang-queries[function interpolation].` ).
58
59
Fields (
@@ -122,14 +123,19 @@ type sftpReader struct {
122
123
watcherMinAge time.Duration
123
124
124
125
// State
125
- stateLock sync.Mutex
126
- scanner codec.DeprecatedFallbackStream
127
- currentPath string
126
+ stateLock sync.Mutex
127
+ scanner codec.DeprecatedFallbackStream
128
+ currentFileInfo currentFileInfo
128
129
129
130
client * clientPool
130
131
pathProvider pathProvider
131
132
}
132
133
134
+ type currentFileInfo struct {
135
+ path string
136
+ modTime time.Time
137
+ }
138
+
133
139
func newSFTPReaderFromParsed (conf * service.ParsedConfig , mgr * service.Resources ) (s * sftpReader , err error ) {
134
140
s = & sftpReader {
135
141
log : mgr .Logger (),
@@ -224,15 +230,16 @@ func (s *sftpReader) tryReadBatch(ctx context.Context) (service.MessageBatch, se
224
230
225
231
_ = s .scanner .Close (ctx )
226
232
s .scanner = nil
227
- s .currentPath = ""
233
+ s .currentFileInfo . path = ""
228
234
if errors .Is (err , io .EOF ) {
229
235
err = service .ErrNotConnected
230
236
}
231
237
return nil , nil , err
232
238
}
233
239
234
240
for _ , part := range parts {
235
- part .MetaSetMut ("sftp_path" , s .currentPath )
241
+ part .MetaSetMut ("sftp_path" , s .currentFileInfo .path )
242
+ part .MetaSetMut ("sftp_mod_time" , s .currentFileInfo .modTime )
236
243
}
237
244
238
245
return parts , codecAckFn , nil
@@ -259,6 +266,11 @@ func (s *sftpReader) initScanner(ctx context.Context) (codec.DeprecatedFallbackS
259
266
return nil , service .ErrEndOfInput
260
267
}
261
268
269
+ fileInfo , err := s .client .Stat (path )
270
+ if err != nil {
271
+ return nil , fmt .Errorf ("stat path: %w" , err )
272
+ }
273
+
262
274
file , err = s .client .Open (path )
263
275
if err != nil {
264
276
s .log .With ("path" , path , "err" , err .Error ()).Warn ("Unable to open previously identified file" )
@@ -284,7 +296,10 @@ func (s *sftpReader) initScanner(ctx context.Context) (codec.DeprecatedFallbackS
284
296
285
297
s .stateLock .Lock ()
286
298
s .scanner = scanner
287
- s .currentPath = path
299
+ s .currentFileInfo = currentFileInfo {
300
+ path : path ,
301
+ modTime : fileInfo .ModTime (),
302
+ }
288
303
s .stateLock .Unlock ()
289
304
return scanner , nil
290
305
}
@@ -335,7 +350,7 @@ func (s *sftpReader) closeScanner(ctx context.Context) {
335
350
s .log .With ("error" , err ).Error ("Failed to close scanner" )
336
351
}
337
352
s .scanner = nil
338
- s .currentPath = ""
353
+ s .currentFileInfo . path = ""
339
354
}
340
355
}
341
356
0 commit comments