@@ -73,14 +73,19 @@ type (
7373
7474 fileManagerServiceInterface interface {
7575 UpdateOverview (ctx context.Context , instanceID string , filesToUpdate []* mpi.File , iteration int ) error
76- ConfigApply (ctx context.Context , configApplyRequest * mpi.ConfigApplyRequest ) (writeStatus model.WriteStatus ,
77- err error )
76+ ConfigApply (
77+ ctx context.Context ,
78+ configApplyRequest * mpi.ConfigApplyRequest ,
79+ ) (writeStatus model.WriteStatus , err error )
7880 Rollback (ctx context.Context , instanceID string ) error
7981 UpdateFile (ctx context.Context , instanceID string , fileToUpdate * mpi.File ) error
8082 ClearCache ()
8183 UpdateCurrentFilesOnDisk (ctx context.Context , updateFiles map [string ]* mpi.File , referenced bool ) error
82- DetermineFileActions (currentFiles map [string ]* mpi.File , modifiedFiles map [string ]* model.FileCache ) (
83- map [string ]* model.FileCache , map [string ][]byte , error )
84+ DetermineFileActions (
85+ ctx context.Context ,
86+ currentFiles map [string ]* mpi.File ,
87+ modifiedFiles map [string ]* model.FileCache ,
88+ ) (map [string ]* model.FileCache , map [string ][]byte , error )
8489 IsConnected () bool
8590 SetIsConnected (isConnected bool )
8691 }
@@ -510,8 +515,11 @@ func (fms *FileManagerService) ConfigApply(ctx context.Context,
510515 return model .Error , allowedErr
511516 }
512517
513- diffFiles , fileContent , compareErr := fms .DetermineFileActions (fms .currentFilesOnDisk ,
514- ConvertToMapOfFileCache (fileOverview .GetFiles ()))
518+ diffFiles , fileContent , compareErr := fms .DetermineFileActions (
519+ ctx ,
520+ fms .currentFilesOnDisk ,
521+ ConvertToMapOfFileCache (fileOverview .GetFiles ()),
522+ )
515523
516524 if compareErr != nil {
517525 return model .Error , compareErr
@@ -546,7 +554,7 @@ func (fms *FileManagerService) ClearCache() {
546554
547555// nolint:revive,cyclop
548556func (fms * FileManagerService ) Rollback (ctx context.Context , instanceID string ) error {
549- slog .InfoContext (ctx , "Rolling back config for instance" , "instanceid " , instanceID )
557+ slog .InfoContext (ctx , "Rolling back config for instance" , "instance_id " , instanceID )
550558
551559 fms .filesMutex .Lock ()
552560 defer fms .filesMutex .Unlock ()
@@ -714,6 +722,7 @@ func (fms *FileManagerService) checkAllowedDirectory(checkFiles []*mpi.File) err
714722// that have changed and a map of the contents for each updated and deleted file. Key to both maps is file path
715723// nolint: revive,cyclop,gocognit
716724func (fms * FileManagerService ) DetermineFileActions (
725+ ctx context.Context ,
717726 currentFiles map [string ]* mpi.File ,
718727 modifiedFiles map [string ]* model.FileCache ,
719728) (
@@ -736,6 +745,7 @@ func (fms *FileManagerService) DetermineFileActions(
736745 return nil , nil , manifestFileErr
737746 }
738747 }
748+
739749 // if file is in manifestFiles but not in modified files, file has been deleted
740750 // copy contents, set file action
741751 for fileName , manifestFile := range filesMap {
@@ -745,7 +755,12 @@ func (fms *FileManagerService) DetermineFileActions(
745755 // Read file contents before marking it deleted
746756 fileContent , readErr := os .ReadFile (fileName )
747757 if readErr != nil {
748- return nil , nil , fmt .Errorf ("error reading file %s: %w" , fileName , readErr )
758+ if errors .Is (readErr , os .ErrNotExist ) {
759+ slog .DebugContext (ctx , "Unable to backup file contents since file does not exist" , "file" , fileName )
760+ continue
761+ } else {
762+ return nil , nil , fmt .Errorf ("error reading file %s: %w" , fileName , readErr )
763+ }
749764 }
750765 fileContents [fileName ] = fileContent
751766
0 commit comments