Skip to content

Commit 56e09fb

Browse files
committed
fix delete file on disk
1 parent 6b72b7b commit 56e09fb

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

internal/file/file_manager_service.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,6 @@ func (fms *FileManagerService) DetermineFileActions(
771771
// if file doesn't exist in the current files, file has been added
772772
// set file action
773773
if _, statErr := os.Stat(modifiedFile.File.GetFileMeta().GetName()); errors.Is(statErr, os.ErrNotExist) {
774-
slog.Info("File is not present on disk", "file", modifiedFile.File.GetFileMeta().GetName())
775774
modifiedFile.Action = model.Add
776775
fileDiff[modifiedFile.File.GetFileMeta().GetName()] = modifiedFile
777776

@@ -824,20 +823,31 @@ func (fms *FileManagerService) UpdateManifestFile(currentFiles map[string]*mpi.F
824823
return fmt.Errorf("unable to read manifest file: %w", readError)
825824
}
826825

827-
manifestFiles := fms.convertToManifestFileMap(currentFiles, referenced)
826+
updatedFiles := make(map[string]*model.ManifestFile)
828827

828+
manifestFiles := fms.convertToManifestFileMap(currentFiles, referenced)
829829
// During a config apply every file is set to unreferenced
830830
// When a new NGINX config context is detected
831831
// we update the files in the manifest by setting the referenced bool to true
832832
if currentManifestFiles != nil && referenced {
833+
for _, currentManifestFile := range currentManifestFiles {
834+
// if file from manifest file is unreferenced add it to updatedFiles map
835+
if !currentManifestFile.ManifestFileMeta.Referenced {
836+
updatedFiles[currentManifestFile.ManifestFileMeta.Name] = currentManifestFile
837+
}
838+
}
833839
for manifestFileName, manifestFile := range manifestFiles {
834-
currentManifestFiles[manifestFileName] = manifestFile
840+
updatedFiles[manifestFileName] = manifestFile
835841
}
836842
} else {
837-
currentManifestFiles = manifestFiles
843+
updatedFiles = manifestFiles
838844
}
839845

840-
manifestJSON, err := json.MarshalIndent(currentManifestFiles, "", " ")
846+
return fms.writeManifestFile(updatedFiles)
847+
}
848+
849+
func (fms *FileManagerService) writeManifestFile(updatedFiles map[string]*model.ManifestFile) error {
850+
manifestJSON, err := json.MarshalIndent(updatedFiles, "", " ")
841851
if err != nil {
842852
return fmt.Errorf("unable to marshal manifest file json: %w", err)
843853
}

0 commit comments

Comments
 (0)