Skip to content

Commit 973777a

Browse files
committed
chore: fixing manifest for delete
1 parent fa85591 commit 973777a

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

internal/file/file_manager_service.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,9 +308,10 @@ func (fms *FileManagerService) ConfigApply(ctx context.Context,
308308
if fileErr != nil {
309309
return model.RollbackRequired, fileErr
310310
}
311-
311+
slog.Error("config apply called")
312312
// Update map of current files on disk
313313
fms.UpdateCurrentFilesOnDisk(files.ConvertToMapOfFiles(fileOverview.GetFiles()))
314+
fms.UpdateManifestFile(files.ConvertToMapOfFiles(fileOverview.GetFiles()))
314315

315316
return model.OK, nil
316317
}
@@ -333,8 +334,9 @@ func (fms *FileManagerService) Rollback(ctx context.Context, instanceID string)
333334

334335
// currentFilesOnDisk needs to be updated after rollback action is performed
335336
delete(fms.currentFilesOnDisk, file.GetFileMeta().GetName())
336-
337+
fms.UpdateManifestFile(fms.currentFilesOnDisk)
337338
continue
339+
338340
case mpi.File_FILE_ACTION_DELETE, mpi.File_FILE_ACTION_UPDATE:
339341
content := fms.rollbackFileContents[file.GetFileMeta().GetName()]
340342

@@ -346,6 +348,8 @@ func (fms *FileManagerService) Rollback(ctx context.Context, instanceID string)
346348
// currentFilesOnDisk needs to be updated after rollback action is performed
347349
file.GetFileMeta().Hash = files.GenerateHash(content)
348350
fms.currentFilesOnDisk[file.GetFileMeta().GetName()] = file
351+
fms.UpdateManifestFile(fms.currentFilesOnDisk)
352+
349353
case mpi.File_FILE_ACTION_UNSPECIFIED, mpi.File_FILE_ACTION_UNCHANGED:
350354
fallthrough
351355
default:
@@ -466,6 +470,7 @@ func (fms *FileManagerService) DetermineFileActions(currentFiles, modifiedFiles
466470
err = json.Unmarshal(file, &manifestFiles)
467471
if err != nil {
468472
fmt.Printf("Failed to parse manifest JSON: %v\n", err)
473+
manifestFiles = currentFiles // This is the first time when config apply is happening.
469474
}
470475

471476
// if file is in manifestFiles but not in modified files, file has been deleted
@@ -528,11 +533,15 @@ func (fms *FileManagerService) UpdateCurrentFilesOnDisk(currentFiles map[string]
528533
fms.currentFilesOnDisk[file.GetFileMeta().GetName()] = file
529534
}
530535

536+
}
537+
538+
func (fms *FileManagerService) UpdateManifestFile(currentFiles map[string]*mpi.File) {
531539
jsonData, err := json.MarshalIndent(currentFiles, "", " ")
532540
if err != nil {
533541
fmt.Printf("Failed to read manifest file: %v\n", err)
534542
}
535543

544+
slog.Error(string(jsonData))
536545
err = os.MkdirAll(manifestDirPath, 0755) // 0755 allows read/execute for all, write for owner
537546
if err != nil {
538547
fmt.Printf("Failed to read manifest file: %v\n", err)

0 commit comments

Comments
 (0)