Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ensure fullpath #471

Merged
merged 1 commit into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 23 additions & 15 deletions src/core/nginx.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,6 @@ 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 @@ -486,7 +485,12 @@ 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 @@ -500,29 +504,34 @@ func (n *NginxBinaryType) writeConfigWithWithFileActions(config *proto.NginxConf

for _, file := range confFiles {
rootDirectoryPath := filepath.Dir(details.ConfPath)
if _, found := filesToUpdate[file.Name]; !found {
log.Debugf("No action found for config file %s.", file.Name)
continue
fileFullPath := file.Name
if !filepath.IsAbs(fileFullPath) {
fileFullPath = filepath.Join(rootDirectoryPath, fileFullPath)
}

delete(filesToUpdate, file.Name)

if err := n.env.WriteFile(configApply, file, rootDirectoryPath); err != nil {
if _, found := filesToUpdate[fileFullPath]; !found {
log.Warnf("No action found for config file %s, assume update.",
fileFullPath)
}
delete(filesToUpdate, fileFullPath)
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()
if _, found := filesToUpdate[file.Name]; !found {
log.Debugf("No action found for aux file %s.", file.Name)
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)
continue
}

delete(filesToUpdate, file.Name)

if err := n.env.WriteFile(configApply, file, rootDirectoryPath); err != nil {
delete(filesToUpdate, fileFullPath)
if err = n.env.WriteFile(configApply, file, rootDirectoryPath); err != nil {
log.Warnf("configuration write failed: %s", err)
return configApply, err
}
Expand Down Expand Up @@ -617,7 +626,6 @@ 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.