Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 6 additions & 3 deletions internal/datasource/config/nginx_config_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func (ncp *NginxConfigParser) createNginxConfigContext(
func(ctx context.Context, parent, directive *crossplane.Directive) error {
switch directive.Directive {
case "include":
include := ncp.parseIncludeDirective(directive)
include := ncp.parseIncludeDirective(directive, &conf)

nginxConfigContext.Includes = append(nginxConfigContext.Includes, include)
case "log_format":
Expand Down Expand Up @@ -267,12 +267,15 @@ func (ncp *NginxConfigParser) findLocalSysLogServers(sysLogServer string) string
return ""
}

func (ncp *NginxConfigParser) parseIncludeDirective(directive *crossplane.Directive) string {
func (ncp *NginxConfigParser) parseIncludeDirective(
directive *crossplane.Directive,
configFile *crossplane.Config,
) string {
var include string
if filepath.IsAbs(directive.Args[0]) {
include = directive.Args[0]
} else {
include = filepath.Join(filepath.Dir(directive.File), directive.Args[0])
include = filepath.Join(filepath.Dir(configFile.File), directive.Args[0])
}

return include
Expand Down
14 changes: 8 additions & 6 deletions internal/watcher/file/file_watcher_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,12 @@ func (fws *FileWatcherService) addWatchers(ctx context.Context) {
}

if !slices.Contains(fws.watcher.WatchList(), directory) {
fws.addWatcher(ctx, directory)
fws.filesChanged.Store(true)
err := fws.addWatcher(ctx, directory)
if err != nil {
slog.DebugContext(ctx, "Failed to add file watcher", "directory", directory, "error", err)
} else {
fws.filesChanged.Store(true)
}
}
}
}
Expand Down Expand Up @@ -208,7 +212,7 @@ func (fws *FileWatcherService) checkForUpdates(ctx context.Context, ch chan<- Fi
}
}

func (fws *FileWatcherService) addWatcher(ctx context.Context, directory string) {
func (fws *FileWatcherService) addWatcher(ctx context.Context, directory string) error {
slog.DebugContext(ctx, "Checking if file watcher needs to be added", "directory", directory)

if _, err := os.Stat(directory); errors.Is(err, os.ErrNotExist) {
Expand All @@ -220,9 +224,7 @@ func (fws *FileWatcherService) addWatcher(ctx context.Context, directory string)

slog.DebugContext(ctx, "Adding watcher", "directory", directory)

if err := fws.watcher.Add(directory); err != nil {
slog.WarnContext(ctx, "Failed to add file watcher", "directory", directory, "error", err)
}
return fws.watcher.Add(directory)
}

func (fws *FileWatcherService) removeWatcher(ctx context.Context, path string) {
Expand Down
4 changes: 2 additions & 2 deletions internal/watcher/file/file_watcher_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func TestFileWatcherService_addWatcher(t *testing.T) {
require.NoError(t, err)
defer os.Remove(testDirectory)

fileWatcherService.addWatcher(ctx, testDirectory)
require.NoError(t, fileWatcherService.addWatcher(ctx, testDirectory))

directoriesBeingWatched := fileWatcherService.watcher.WatchList()
assert.Len(t, directoriesBeingWatched, 1)
Expand All @@ -79,7 +79,7 @@ func TestFileWatcherService_addWatcher_Error(t *testing.T) {
tempDir := t.TempDir()
testDirectory := path.Join(tempDir, "test_dir")

fileWatcherService.addWatcher(ctx, testDirectory)
require.Error(t, fileWatcherService.addWatcher(ctx, testDirectory))

directoriesBeingWatched := fileWatcherService.watcher.WatchList()
assert.Empty(t, directoriesBeingWatched)
Expand Down