8000 Revert "[Release 3.0.2] Merge back into main (#1133)" (#1135) · nginx/agent@9cfefb8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9cfefb8

Browse files
authored
Revert "[Release 3.0.2] Merge back into main (#1133)" (#1135)
This reverts commit 699efa2.
1 parent 699efa2 commit 9cfefb8

File tree

4 files changed

+24
-56
lines changed

4 files changed

+24
-56
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module github.com/nginx/agent/v3
22

33
go 1.23.7
44

5-
toolchain go1.23.10
5+
toolchain go1.23.8
66

77
require (
88
buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.36.4-20250130201111-63bb56e20495.1

internal/file/file_manager_service.go

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -68,19 +68,14 @@ type (
6868

6969
fileManagerServiceInterface interface {
7070
UpdateOverview(ctx context.Context, instanceID string, filesToUpdate []*mpi.File, iteration int) error
71-
ConfigApply(
72-
ctx context.Context,
73-
configApplyRequest *mpi.ConfigApplyRequest,
74-
) (writeStatus model.WriteStatus, err error)
71+
ConfigApply(ctx context.Context, configApplyRequest *mpi.ConfigApplyRequest) (writeStatus model.WriteStatus,
72+
err error)
7573
Rollback(ctx context.Context, instanceID string) error
7674
UpdateFile(ctx context.Context, instanceID string, fileToUpdate *mpi.File) error
7775
ClearCache()
7876
UpdateCurrentFilesOnDisk(ctx context.Context, updateFiles map[string]*mpi.File, referenced bool) 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)
77+
DetermineFileActions(currentFiles map[string]*mpi.File, modifiedFiles map[string]*model.FileCache) (
78+
map[string]*model.FileCache, map[string][]byte, error)
8479
IsConnected() bool
8580
SetIsConnected(isConnected bool)
8681
}
@@ -510,11 +505,8 @@ func (fms *FileManagerService) ConfigApply(ctx context.Context,
510505
return model.Error, allowedErr
511506
}
512507

513-
diffFiles, fileContent, compareErr := fms.DetermineFileActions(
514-
ctx,
515-
fms.currentFilesOnDisk,
516-
ConvertToMapOfFileCache(fileOverview.GetFiles()),
517-
)
508+
diffFiles, fileContent, compareErr := fms.DetermineFileActions(fms.currentFilesOnDisk,
509+
ConvertToMapOfFileCache(fileOverview.GetFiles()))
518510

519511
if compareErr != nil {
520512
return model.Error, compareErr
@@ -549,7 +541,7 @@ func (fms *FileManagerService) ClearCache() {
549541

550542
// nolint:revive,cyclop
551543
func (fms *FileManagerService) Rollback(ctx context.Context, instanceID string) error {
552-
slog.InfoContext(ctx, "Rolling back config for instance", "instance_id", instanceID)
544+
slog.InfoContext(ctx, "Rolling back config for instance", "instanceid", instanceID)
553545

554546
fms.filesMutex.Lock()
555547
defer fms.filesMutex.Unlock()
@@ -718,7 +710,6 @@ func (fms *FileManagerService) checkAllowedDirectory(checkFiles []*mpi.File) err
718710
// that have changed and a map of the contents for each updated and deleted file. Key to both maps is file path
719711
// nolint: revive,cyclop,gocognit
720712
func (fms *FileManagerService) DetermineFileActions(
721-
ctx context.Context,
722713
currentFiles map[string]*mpi.File,
723714
modifiedFiles map[string]*model.FileCache,
724715
) (
@@ -741,7 +732,6 @@ func (fms *FileManagerService) DetermineFileActions(
741732
return nil, nil, manifestFileErr
742733
}
743734
}
744-
745735
// if file is in manifestFiles but not in modified files, file has been deleted
746736
// copy contents, set file action
747737
for fileName, manifestFile := range filesMap {
@@ -751,12 +741,7 @@ func (fms *FileManagerService) DetermineFileActions(
751741
// Read file contents before marking it deleted
752742
fileContent, readErr := os.ReadFile(fileName)
753743
if readErr != nil {
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-
}
744+
return nil, nil, fmt.Errorf("error reading file %s: %w", fileName, readErr)
760745
}
761746
fileContents[fileName] = fileContent
762747

internal/file/file_manager_service_test.go

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,6 @@ func TestFileManagerService_Rollback(t *testing.T) {
559559
}
560560

561561
func TestFileManagerService_DetermineFileActions(t *testing.T) {
562-
ctx := context.Background()
563562
tempDir := os.TempDir()
564563

565564
deleteTestFile := helpers.CreateFileWithErrorCheck(t, tempDir, "nginx_delete.conf")
@@ -585,6 +584,7 @@ func TestFileManagerService_DetermineFileActions(t *testing.T) {
585584

586585
addTestFile := helpers.CreateFileWithErrorCheck(t, tempDir, "nginx_add.conf")
587586
defer helpers.RemoveFileWithErrorCheck(t, addTestFile.Name())
587+
t.Logf("Adding file: %s", addTestFile.Name())
588588
addFileContent := []byte("test add file")
589589
addErr := os.WriteFile(addTestFile.Name(), addFileContent, 0o600)
590590
require.NoError(t, addErr)
@@ -694,18 +694,6 @@ func TestFileManagerService_DetermineFileActions(t *testing.T) {
694694
expectedContent: make(map[string][]byte),
695695
expectedError: nil,
696696
},
697-
{
698-
name: "Test 3: File being deleted already doesn't exist",
699-
modifiedFiles: make(map[string]*model.FileCache),
700-
currentFiles: map[string]*mpi.File{
701-
"/unknown/file.conf": {
702-
FileMeta: protos.FileMeta("/unknown/file.conf", files.GenerateHash(fileContent)),
703-
},
704-
},
705-
expectedCache: make(map[string]*model.FileCache),
706-
expectedContent: make(map[string][]byte),
707-
expectedError: nil,
708-
},
709697
}
710698

711699
for _, test := range tests {
@@ -723,11 +711,8 @@ func TestFileManagerService_DetermineFileActions(t *testing.T) {
723711

724712
require.NoError(tt, err)
725713

726-
diff, contents, fileActionErr := fileManagerService.DetermineFileActions(
727-
ctx,
728-
test.currentFiles,
729-
test.modifiedFiles,
730-
)
714+
diff, contents, fileActionErr := fileManagerService.DetermineFileActions(test.currentFiles,
715+
test.modifiedFiles)
731716
require.NoError(tt, fileActionErr)
732717
assert.Equal(tt, test.expectedContent, contents)
733718
assert.Equal(tt, test.expectedCache, diff)

internal/file/filefakes/fake_file_manager_service_interface.go

Lines changed: 12 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
0