From 625b7f0f2a42df2dc805d17eaf08e7744eca9f71 Mon Sep 17 00:00:00 2001 From: oliveromahony Date: Tue, 12 Sep 2023 14:05:17 +0100 Subject: [PATCH] Revert "fix: ensure fullpath (#471)" This reverts commit 9a61fc7c791b009acdf01b336608339a054f670c. --- src/core/nginx.go | 38 ++++++++----------- .../nginx/agent/v2/src/core/nginx.go | 38 ++++++++----------- .../nginx/agent/v2/src/core/nginx.go | 38 ++++++++----------- 3 files changed, 45 insertions(+), 69 deletions(-) diff --git a/src/core/nginx.go b/src/core/nginx.go index f29f410ee1..584dd1d226 100644 --- a/src/core/nginx.go +++ b/src/core/nginx.go @@ -401,6 +401,7 @@ func (n *NginxBinaryType) WriteConfig(config *proto.NginxConfig) (*sdk.ConfigApp var configApply *sdk.ConfigApply filesToUpdate, filesToDelete, allFilesHaveAnAction := generateActionMaps(config.DirectoryMap, n.config.AllowedDirectoriesMap) + if allFilesHaveAnAction { configApply, err = n.writeConfigWithWithFileActions(config, details, filesToUpdate, filesToDelete) } else { @@ -485,12 +486,7 @@ func (n *NginxBinaryType) writeConfigWithNoFileActions(details *proto.NginxDetai return configApply, nil } -func (n *NginxBinaryType) writeConfigWithWithFileActions( - config *proto.NginxConfig, - details *proto.NginxDetails, - filesToUpdate map[string]proto.File_Action, - filesToDelete map[string]proto.File_Action, -) (*sdk.ConfigApply, error) { +func (n *NginxBinaryType) writeConfigWithWithFileActions(config *proto.NginxConfig, details *proto.NginxDetails, filesToUpdate map[string]proto.File_Action, filesToDelete map[string]proto.File_Action) (*sdk.ConfigApply, error) { confFiles, auxFiles, err := sdk.GetNginxConfigFiles(config) if err != nil { return nil, err @@ -504,16 +500,14 @@ func (n *NginxBinaryType) writeConfigWithWithFileActions( for _, file := range confFiles { rootDirectoryPath := filepath.Dir(details.ConfPath) - fileFullPath := file.Name - if !filepath.IsAbs(fileFullPath) { - fileFullPath = filepath.Join(rootDirectoryPath, fileFullPath) - } - if _, found := filesToUpdate[fileFullPath]; !found { - log.Warnf("No action found for config file %s, assume update.", - fileFullPath) + if _, found := filesToUpdate[file.Name]; !found { + log.Debugf("No action found for config file %s.", file.Name) + continue } - delete(filesToUpdate, fileFullPath) - if err = n.env.WriteFile(configApply, file, rootDirectoryPath); err != nil { + + delete(filesToUpdate, file.Name) + + if err := n.env.WriteFile(configApply, file, rootDirectoryPath); err != nil { log.Warnf("configuration write failed: %s", err) return configApply, err } @@ -521,17 +515,14 @@ func (n *NginxBinaryType) writeConfigWithWithFileActions( for _, file := range auxFiles { rootDirectoryPath := config.GetZaux().GetRootDirectory() - fileFullPath := file.Name - if !filepath.IsAbs(fileFullPath) { - fileFullPath = filepath.Join(rootDirectoryPath, fileFullPath) - } - if _, found := filesToUpdate[fileFullPath]; !found { - log.Debugf("No action found for aux file %s.", fileFullPath) + if _, found := filesToUpdate[file.Name]; !found { + log.Debugf("No action found for aux file %s.", file.Name) continue } - delete(filesToUpdate, fileFullPath) - if err = n.env.WriteFile(configApply, file, rootDirectoryPath); err != nil { + delete(filesToUpdate, file.Name) + + if err := n.env.WriteFile(configApply, file, rootDirectoryPath); err != nil { log.Warnf("configuration write failed: %s", err) return configApply, err } @@ -626,6 +617,7 @@ func generateActionMaps( filesToDelete[path] = f.Action continue } + } } diff --git a/test/integration/vendor/github.com/nginx/agent/v2/src/core/nginx.go b/test/integration/vendor/github.com/nginx/agent/v2/src/core/nginx.go index f29f410ee1..584dd1d226 100644 --- a/test/integration/vendor/github.com/nginx/agent/v2/src/core/nginx.go +++ b/test/integration/vendor/github.com/nginx/agent/v2/src/core/nginx.go @@ -401,6 +401,7 @@ func (n *NginxBinaryType) WriteConfig(config *proto.NginxConfig) (*sdk.ConfigApp var configApply *sdk.ConfigApply filesToUpdate, filesToDelete, allFilesHaveAnAction := generateActionMaps(config.DirectoryMap, n.config.AllowedDirectoriesMap) + if allFilesHaveAnAction { configApply, err = n.writeConfigWithWithFileActions(config, details, filesToUpdate, filesToDelete) } else { @@ -485,12 +486,7 @@ func (n *NginxBinaryType) writeConfigWithNoFileActions(details *proto.NginxDetai return configApply, nil } -func (n *NginxBinaryType) writeConfigWithWithFileActions( - config *proto.NginxConfig, - details *proto.NginxDetails, - filesToUpdate map[string]proto.File_Action, - filesToDelete map[string]proto.File_Action, -) (*sdk.ConfigApply, error) { +func (n *NginxBinaryType) writeConfigWithWithFileActions(config *proto.NginxConfig, details *proto.NginxDetails, filesToUpdate map[string]proto.File_Action, filesToDelete map[string]proto.File_Action) (*sdk.ConfigApply, error) { confFiles, auxFiles, err := sdk.GetNginxConfigFiles(config) if err != nil { return nil, err @@ -504,16 +500,14 @@ func (n *NginxBinaryType) writeConfigWithWithFileActions( for _, file := range confFiles { rootDirectoryPath := filepath.Dir(details.ConfPath) - fileFullPath := file.Name - if !filepath.IsAbs(fileFullPath) { - fileFullPath = filepath.Join(rootDirectoryPath, fileFullPath) - } - if _, found := filesToUpdate[fileFullPath]; !found { - log.Warnf("No action found for config file %s, assume update.", - fileFullPath) + if _, found := filesToUpdate[file.Name]; !found { + log.Debugf("No action found for config file %s.", file.Name) + continue } - delete(filesToUpdate, fileFullPath) - if err = n.env.WriteFile(configApply, file, rootDirectoryPath); err != nil { + + delete(filesToUpdate, file.Name) + + if err := n.env.WriteFile(configApply, file, rootDirectoryPath); err != nil { log.Warnf("configuration write failed: %s", err) return configApply, err } @@ -521,17 +515,14 @@ func (n *NginxBinaryType) writeConfigWithWithFileActions( for _, file := range auxFiles { rootDirectoryPath := config.GetZaux().GetRootDirectory() - fileFullPath := file.Name - if !filepath.IsAbs(fileFullPath) { - fileFullPath = filepath.Join(rootDirectoryPath, fileFullPath) - } - if _, found := filesToUpdate[fileFullPath]; !found { - log.Debugf("No action found for aux file %s.", fileFullPath) + if _, found := filesToUpdate[file.Name]; !found { + log.Debugf("No action found for aux file %s.", file.Name) continue } - delete(filesToUpdate, fileFullPath) - if err = n.env.WriteFile(configApply, file, rootDirectoryPath); err != nil { + delete(filesToUpdate, file.Name) + + if err := n.env.WriteFile(configApply, file, rootDirectoryPath); err != nil { log.Warnf("configuration write failed: %s", err) return configApply, err } @@ -626,6 +617,7 @@ func generateActionMaps( filesToDelete[path] = f.Action continue } + } } diff --git a/test/performance/vendor/github.com/nginx/agent/v2/src/core/nginx.go b/test/performance/vendor/github.com/nginx/agent/v2/src/core/nginx.go index f29f410ee1..584dd1d226 100644 --- a/test/performance/vendor/github.com/nginx/agent/v2/src/core/nginx.go +++ b/test/performance/vendor/github.com/nginx/agent/v2/src/core/nginx.go @@ -401,6 +401,7 @@ func (n *NginxBinaryType) WriteConfig(config *proto.NginxConfig) (*sdk.ConfigApp var configApply *sdk.ConfigApply filesToUpdate, filesToDelete, allFilesHaveAnAction := generateActionMaps(config.DirectoryMap, n.config.AllowedDirectoriesMap) + if allFilesHaveAnAction { configApply, err = n.writeConfigWithWithFileActions(config, details, filesToUpdate, filesToDelete) } else { @@ -485,12 +486,7 @@ func (n *NginxBinaryType) writeConfigWithNoFileActions(details *proto.NginxDetai return configApply, nil } -func (n *NginxBinaryType) writeConfigWithWithFileActions( - config *proto.NginxConfig, - details *proto.NginxDetails, - filesToUpdate map[string]proto.File_Action, - filesToDelete map[string]proto.File_Action, -) (*sdk.ConfigApply, error) { +func (n *NginxBinaryType) writeConfigWithWithFileActions(config *proto.NginxConfig, details *proto.NginxDetails, filesToUpdate map[string]proto.File_Action, filesToDelete map[string]proto.File_Action) (*sdk.ConfigApply, error) { confFiles, auxFiles, err := sdk.GetNginxConfigFiles(config) if err != nil { return nil, err @@ -504,16 +500,14 @@ func (n *NginxBinaryType) writeConfigWithWithFileActions( for _, file := range confFiles { rootDirectoryPath := filepath.Dir(details.ConfPath) - fileFullPath := file.Name - if !filepath.IsAbs(fileFullPath) { - fileFullPath = filepath.Join(rootDirectoryPath, fileFullPath) - } - if _, found := filesToUpdate[fileFullPath]; !found { - log.Warnf("No action found for config file %s, assume update.", - fileFullPath) + if _, found := filesToUpdate[file.Name]; !found { + log.Debugf("No action found for config file %s.", file.Name) + continue } - delete(filesToUpdate, fileFullPath) - if err = n.env.WriteFile(configApply, file, rootDirectoryPath); err != nil { + + delete(filesToUpdate, file.Name) + + if err := n.env.WriteFile(configApply, file, rootDirectoryPath); err != nil { log.Warnf("configuration write failed: %s", err) return configApply, err } @@ -521,17 +515,14 @@ func (n *NginxBinaryType) writeConfigWithWithFileActions( for _, file := range auxFiles { rootDirectoryPath := config.GetZaux().GetRootDirectory() - fileFullPath := file.Name - if !filepath.IsAbs(fileFullPath) { - fileFullPath = filepath.Join(rootDirectoryPath, fileFullPath) - } - if _, found := filesToUpdate[fileFullPath]; !found { - log.Debugf("No action found for aux file %s.", fileFullPath) + if _, found := filesToUpdate[file.Name]; !found { + log.Debugf("No action found for aux file %s.", file.Name) continue } - delete(filesToUpdate, fileFullPath) - if err = n.env.WriteFile(configApply, file, rootDirectoryPath); err != nil { + delete(filesToUpdate, file.Name) + + if err := n.env.WriteFile(configApply, file, rootDirectoryPath); err != nil { log.Warnf("configuration write failed: %s", err) return configApply, err } @@ -626,6 +617,7 @@ func generateActionMaps( filesToDelete[path] = f.Action continue } + } }