@@ -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,20 @@ 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
+ currentPath string
129
+ currentFileInfo currentFileInfo
128
130
129
131
client * clientPool
130
132
pathProvider pathProvider
131
133
}
132
134
135
+ type currentFileInfo struct {
136
+ path string
137
+ modTime time.Time
138
+ }
139
+
133
140
func newSFTPReaderFromParsed (conf * service.ParsedConfig , mgr * service.Resources ) (s * sftpReader , err error ) {
134
141
s = & sftpReader {
135
142
log : mgr .Logger (),
@@ -233,6 +240,7 @@ func (s *sftpReader) tryReadBatch(ctx context.Context) (service.MessageBatch, se
233
240
234
241
for _ , part := range parts {
235
242
part .MetaSetMut ("sftp_path" , s .currentPath )
243
+ part .MetaSetMut ("sftp_mod_time" , s .currentFileInfo .modTime )
236
244
}
237
245
238
246
return parts , codecAckFn , nil
@@ -259,6 +267,11 @@ func (s *sftpReader) initScanner(ctx context.Context) (codec.DeprecatedFallbackS
259
267
return nil , service .ErrEndOfInput
260
268
}
261
269
270
+ fileInfo , err := s .client .Stat (path )
271
+ if err != nil {
272
+ return nil , fmt .Errorf ("stat path: %w" , err )
273
+ }
274
+
262
275
file , err = s .client .Open (path )
263
276
if err != nil {
264
277
s .log .With ("path" , path , "err" , err .Error ()).Warn ("Unable to open previously identified file" )
@@ -285,6 +298,10 @@ func (s *sftpReader) initScanner(ctx context.Context) (codec.DeprecatedFallbackS
285
298
s .stateLock .Lock ()
286
299
s .scanner = scanner
287
300
s .currentPath = path
301
+ s .currentFileInfo = currentFileInfo {
302
+ path : path ,
303
+ modTime : fileInfo .ModTime (),
304
+ }
288
305
s .stateLock .Unlock ()
289
306
return scanner , nil
290
307
}
0 commit comments