@@ -7,6 +7,7 @@ package file
77
88import (
99 "context"
10+ "encoding/json"
1011 "errors"
1112 "fmt"
1213 "log/slog"
@@ -70,6 +71,7 @@ type FileManagerService struct {
7071 // map of the files currently on disk, used to determine the file action during config apply
7172 currentFilesOnDisk map [string ]* mpi.File // key is file path
7273 filesMutex sync.RWMutex
74+ manifestFilePath string
7375}
7476
7577func NewFileManagerService (fileServiceClient mpi.FileServiceClient , agentConfig * config.Config ) * FileManagerService {
@@ -510,4 +512,23 @@ func (fms *FileManagerService) UpdateCurrentFilesOnDisk(currentFiles map[string]
510512 for _ , file := range currentFiles {
511513 fms .currentFilesOnDisk [file .GetFileMeta ().GetName ()] = file
512514 }
515+
516+ if err := fms .writeManifest (); err != nil {
517+ // Handle error (e.g., logging)
518+ }
519+ }
520+
521+ // writeManifest writes the currentFilesOnDisk to a JSON manifest file
522+ func (fms * FileManagerService ) writeManifest () error {
523+ fileList := make ([]string , 0 , len (fms .currentFilesOnDisk ))
524+ for name := range fms .currentFilesOnDisk {
525+ fileList = append (fileList , name )
526+ }
527+
528+ data , err := json .MarshalIndent (fileList , "" , " " )
529+ if err != nil {
530+ return err
531+ }
532+
533+ return os .WriteFile (fms .manifestFilePath , data , 0640 )
513534}
0 commit comments