6161 Rollback (ctx context.Context , instanceID string ) error
6262 UpdateFile (ctx context.Context , instanceID string , fileToUpdate * mpi.File ) error
6363 ClearCache ()
64- UpdateCurrentFilesOnDisk (updateFiles map [string ]* mpi.File )
64+ UpdateCurrentFilesOnDisk (ctx context. Context , updateFiles map [string ]* mpi.File )
6565 DetermineFileActions (currentFiles map [string ]* mpi.File , modifiedFiles map [string ]* model.FileCache ) (
6666 map [string ]* model.FileCache , map [string ][]byte , error )
6767 IsConnected () bool
@@ -325,7 +325,7 @@ func (fms *FileManagerService) ConfigApply(ctx context.Context,
325325 }
326326 fileOverviewFiles := files .ConvertToMapOfFiles (fileOverview .GetFiles ())
327327 // Update map of current files on disk
328- fms .UpdateCurrentFilesOnDisk (fileOverviewFiles )
328+ fms .UpdateCurrentFilesOnDisk (ctx , fileOverviewFiles )
329329 manifestFileErr := fms .UpdateManifestFile (fileOverviewFiles )
330330 if manifestFileErr != nil {
331331 return model .RollbackRequired , manifestFileErr
@@ -479,10 +479,14 @@ func (fms *FileManagerService) DetermineFileActions(currentFiles map[string]*mpi
479479 fileDiff := make (map [string ]* model.FileCache ) // Files that have changed, key is file name
480480 fileContents := make (map [string ][]byte ) // contents of the file, key is file name
481481
482- manifestFiles , manifestFileErr := fms .manifestFile (currentFiles )
482+ manifestFiles , manifestFileErr := fms .manifestFile ()
483483
484- if manifestFileErr != nil && manifestFiles == nil {
485- return nil , nil , manifestFileErr
484+ if manifestFileErr != nil {
485+ if errors .Is (manifestFileErr , os .ErrNotExist ) {
486+ manifestFiles = currentFiles
487+ } else {
488+ return nil , nil , manifestFileErr
489+ }
486490 }
487491 // if file is in manifestFiles but not in modified files, file has been deleted
488492 // copy contents, set file action
@@ -537,7 +541,7 @@ func (fms *FileManagerService) DetermineFileActions(currentFiles map[string]*mpi
537541
538542// UpdateCurrentFilesOnDisk updates the FileManagerService currentFilesOnDisk slice which contains the files
539543// currently on disk
540- func (fms * FileManagerService ) UpdateCurrentFilesOnDisk (currentFiles map [string ]* mpi.File ) {
544+ func (fms * FileManagerService ) UpdateCurrentFilesOnDisk (ctx context. Context , currentFiles map [string ]* mpi.File ) {
541545 fms .filesMutex .Lock ()
542546 defer fms .filesMutex .Unlock ()
543547
@@ -546,6 +550,11 @@ func (fms *FileManagerService) UpdateCurrentFilesOnDisk(currentFiles map[string]
546550 for _ , currentFile := range currentFiles {
547551 fms .currentFilesOnDisk [currentFile .GetFileMeta ().GetName ()] = currentFile
548552 }
553+
554+ err := fms .UpdateManifestFile (currentFiles )
555+ if err != nil {
556+ slog .ErrorContext (ctx , "Failed to update manifest file" , "error" , err )
557+ }
549558}
550559
551560func (fms * FileManagerService ) UpdateManifestFile (currentFiles map [string ]* mpi.File ) (err error ) {
@@ -575,9 +584,9 @@ func (fms *FileManagerService) UpdateManifestFile(currentFiles map[string]*mpi.F
575584 return nil
576585}
577586
578- func (fms * FileManagerService ) manifestFile (currentFiles map [ string ] * mpi. File ) (map [string ]* mpi.File , error ) {
587+ func (fms * FileManagerService ) manifestFile () (map [string ]* mpi.File , error ) {
579588 if _ , err := os .Stat (manifestFilePath ); err != nil {
580- return currentFiles , err // Return current files if manifest directory still doesn't exist
589+ return nil , err
581590 }
582591
583592 file , err := os .ReadFile (manifestFilePath )
0 commit comments