Skip to content

Commit 9a61fc7

Browse files
fix: ensure fullpath (#471)
Co-authored-by: Nick Chen <[email protected]>
1 parent 26e43d6 commit 9a61fc7

File tree

3 files changed

+69
-45
lines changed
  • src/core
  • test
    • integration/vendor/github.com/nginx/agent/v2/src/core
    • performance/vendor/github.com/nginx/agent/v2/src/core

3 files changed

+69
-45
lines changed

src/core/nginx.go

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,6 @@ func (n *NginxBinaryType) WriteConfig(config *proto.NginxConfig) (*sdk.ConfigApp
401401
var configApply *sdk.ConfigApply
402402

403403
filesToUpdate, filesToDelete, allFilesHaveAnAction := generateActionMaps(config.DirectoryMap, n.config.AllowedDirectoriesMap)
404-
405404
if allFilesHaveAnAction {
406405
configApply, err = n.writeConfigWithWithFileActions(config, details, filesToUpdate, filesToDelete)
407406
} else {
@@ -486,7 +485,12 @@ func (n *NginxBinaryType) writeConfigWithNoFileActions(details *proto.NginxDetai
486485
return configApply, nil
487486
}
488487

489-
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) {
488+
func (n *NginxBinaryType) writeConfigWithWithFileActions(
489+
config *proto.NginxConfig,
490+
details *proto.NginxDetails,
491+
filesToUpdate map[string]proto.File_Action,
492+
filesToDelete map[string]proto.File_Action,
493+
) (*sdk.ConfigApply, error) {
490494
confFiles, auxFiles, err := sdk.GetNginxConfigFiles(config)
491495
if err != nil {
492496
return nil, err
@@ -500,29 +504,34 @@ func (n *NginxBinaryType) writeConfigWithWithFileActions(config *proto.NginxConf
500504

501505
for _, file := range confFiles {
502506
rootDirectoryPath := filepath.Dir(details.ConfPath)
503-
if _, found := filesToUpdate[file.Name]; !found {
504-
log.Debugf("No action found for config file %s.", file.Name)
505-
continue
507+
fileFullPath := file.Name
508+
if !filepath.IsAbs(fileFullPath) {
509+
fileFullPath = filepath.Join(rootDirectoryPath, fileFullPath)
506510
}
507-
508-
delete(filesToUpdate, file.Name)
509-
510-
if err := n.env.WriteFile(configApply, file, rootDirectoryPath); err != nil {
511+
if _, found := filesToUpdate[fileFullPath]; !found {
512+
log.Warnf("No action found for config file %s, assume update.",
513+
fileFullPath)
514+
}
515+
delete(filesToUpdate, fileFullPath)
516+
if err = n.env.WriteFile(configApply, file, rootDirectoryPath); err != nil {
511517
log.Warnf("configuration write failed: %s", err)
512518
return configApply, err
513519
}
514520
}
515521

516522
for _, file := range auxFiles {
517523
rootDirectoryPath := config.GetZaux().GetRootDirectory()
518-
if _, found := filesToUpdate[file.Name]; !found {
519-
log.Debugf("No action found for aux file %s.", file.Name)
524+
fileFullPath := file.Name
525+
if !filepath.IsAbs(fileFullPath) {
526+
fileFullPath = filepath.Join(rootDirectoryPath, fileFullPath)
527+
}
528+
if _, found := filesToUpdate[fileFullPath]; !found {
529+
log.Debugf("No action found for aux file %s.", fileFullPath)
520530
continue
521531
}
522532

523-
delete(filesToUpdate, file.Name)
524-
525-
if err := n.env.WriteFile(configApply, file, rootDirectoryPath); err != nil {
533+
delete(filesToUpdate, fileFullPath)
534+
if err = n.env.WriteFile(configApply, file, rootDirectoryPath); err != nil {
526535
log.Warnf("configuration write failed: %s", err)
527536
return configApply, err
528537
}
@@ -617,7 +626,6 @@ func generateActionMaps(
617626
filesToDelete[path] = f.Action
618627
continue
619628
}
620-
621629
}
622630
}
623631

test/integration/vendor/github.com/nginx/agent/v2/src/core/nginx.go

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

test/performance/vendor/github.com/nginx/agent/v2/src/core/nginx.go

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

0 commit comments

Comments
 (0)