Skip to content

Commit

Permalink
Revert "fix: ensure fullpath (#471)"
Browse files Browse the repository at this point in the history
This reverts commit 9a61fc7.
  • Loading branch information
oliveromahony authored Sep 12, 2023
1 parent 9a61fc7 commit 625b7f0
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 69 deletions.
38 changes: 15 additions & 23 deletions src/core/nginx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -504,34 +500,29 @@ 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
}
}

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
}
Expand Down Expand Up @@ -626,6 +617,7 @@ func generateActionMaps(
filesToDelete[path] = f.Action
continue
}

}
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 625b7f0

Please sign in to comment.