Skip to content

Commit

Permalink
fix: ensure fullpath
Browse files Browse the repository at this point in the history
  • Loading branch information
nickchen committed Sep 11, 2023
1 parent 26e43d6 commit 9a7b722
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 45 deletions.
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.

0 comments on commit 9a7b722

Please sign in to comment.