@@ -68,14 +68,19 @@ type (
6868
6969 fileManagerServiceInterface interface {
7070 UpdateOverview (ctx context.Context , instanceID string , filesToUpdate []* mpi.File , iteration int ) error
71- ConfigApply (ctx context.Context , configApplyRequest * mpi.ConfigApplyRequest ) (writeStatus model.WriteStatus ,
72- err error )
71+ ConfigApply (
72+ ctx context.Context ,
73+ configApplyRequest * mpi.ConfigApplyRequest ,
74+ ) (writeStatus model.WriteStatus , err error )
7375 Rollback (ctx context.Context , instanceID string ) error
7476 UpdateFile (ctx context.Context , instanceID string , fileToUpdate * mpi.File ) error
7577 ClearCache ()
7678 UpdateCurrentFilesOnDisk (ctx context.Context , updateFiles map [string ]* mpi.File , referenced bool ) error
77- DetermineFileActions (currentFiles map [string ]* mpi.File , modifiedFiles map [string ]* model.FileCache ) (
78- map [string ]* model.FileCache , map [string ][]byte , error )
79+ DetermineFileActions (
80+ ctx context.Context ,
81+ currentFiles map [string ]* mpi.File ,
82+ modifiedFiles map [string ]* model.FileCache ,
83+ ) (map [string ]* model.FileCache , map [string ][]byte , error )
7984 IsConnected () bool
8085 SetIsConnected (isConnected bool )
8186 }
@@ -505,8 +510,11 @@ func (fms *FileManagerService) ConfigApply(ctx context.Context,
505510 return model .Error , allowedErr
506511 }
507512
508- diffFiles , fileContent , compareErr := fms .DetermineFileActions (fms .currentFilesOnDisk ,
509- ConvertToMapOfFileCache (fileOverview .GetFiles ()))
513+ diffFiles , fileContent , compareErr := fms .DetermineFileActions (
514+ ctx ,
515+ fms .currentFilesOnDisk ,
516+ ConvertToMapOfFileCache (fileOverview .GetFiles ()),
517+ )
510518
511519 if compareErr != nil {
512520 return model .Error , compareErr
@@ -541,7 +549,7 @@ func (fms *FileManagerService) ClearCache() {
541549
542550// nolint:revive,cyclop
543551func (fms * FileManagerService ) Rollback (ctx context.Context , instanceID string ) error {
544- slog .InfoContext (ctx , "Rolling back config for instance" , "instanceid " , instanceID )
552+ slog .InfoContext (ctx , "Rolling back config for instance" , "instance_id " , instanceID )
545553
546554 fms .filesMutex .Lock ()
547555 defer fms .filesMutex .Unlock ()
@@ -710,6 +718,7 @@ func (fms *FileManagerService) checkAllowedDirectory(checkFiles []*mpi.File) err
710718// that have changed and a map of the contents for each updated and deleted file. Key to both maps is file path
711719// nolint: revive,cyclop,gocognit
712720func (fms * FileManagerService ) DetermineFileActions (
721+ ctx context.Context ,
713722 currentFiles map [string ]* mpi.File ,
714723 modifiedFiles map [string ]* model.FileCache ,
715724) (
@@ -732,6 +741,7 @@ func (fms *FileManagerService) DetermineFileActions(
732741 return nil , nil , manifestFileErr
733742 }
734743 }
744+
735745 // if file is in manifestFiles but not in modified files, file has been deleted
736746 // copy contents, set file action
737747 for fileName , manifestFile := range filesMap {
@@ -741,7 +751,12 @@ func (fms *FileManagerService) DetermineFileActions(
741751 // Read file contents before marking it deleted
742752 fileContent , readErr := os .ReadFile (fileName )
743753 if readErr != nil {
744- return nil , nil , fmt .Errorf ("error reading file %s: %w" , fileName , readErr )
754+ if errors .Is (readErr , os .ErrNotExist ) {
755+ slog .DebugContext (ctx , "Unable to backup file contents since file does not exist" , "file" , fileName )
756+ continue
757+ } else {
758+ return nil , nil , fmt .Errorf ("error reading file %s: %w" , fileName , readErr )
759+ }
745760 }
746761 fileContents [fileName ] = fileContent
747762
0 commit comments