Skip to content

Commit ec69dd8

Browse files
committed
feat: create manifest file
1 parent 0024261 commit ec69dd8

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

internal/file/file_manager_service.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package file
77

88
import (
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

7577
func 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

Comments
 (0)