From 6c895b496ad60fa41756d794ef1ac4b281a2eca5 Mon Sep 17 00:00:00 2001 From: AhmedGrati Date: Fri, 8 Sep 2023 19:03:15 +0100 Subject: [PATCH] feat: ignore hidden feature files Signed-off-by: AhmedGrati --- docs/usage/customization-guide.md | 10 ++++++---- source/local/local.go | 8 ++++++++ source/local/testdata/features.d/.my.feature | 1 + 3 files changed, 15 insertions(+), 4 deletions(-) create mode 100644 source/local/testdata/features.d/.my.feature diff --git a/docs/usage/customization-guide.md b/docs/usage/customization-guide.md index ae9b2d2fd..17096ac61 100644 --- a/docs/usage/customization-guide.md +++ b/docs/usage/customization-guide.md @@ -234,10 +234,12 @@ further be used in label rules specified in [`custom`](#custom-feature-source) feature source. > **NOTE:** Be careful when creating and/or updating hook or feature files -> while NFD is running. In order to avoid race conditions you should write into -> a temporary file (outside the `source.d` and `features.d` directories), and, -> atomically create/update the original file by doing a filesystem move -> operation. +> while NFD is running. In order to avoid race conditions you should write +> into a temporary file, and atomically create/update the original file by +> doing a file rename operation. NFD ignores dot files, +> so temporary file can be written to the same directory and renamed +> (`.my.feature` -> `my.feature`) once file is complete. Both file names should +> (obviously) be unique for the given application. ### An example diff --git a/source/local/local.go b/source/local/local.go index a39fea9ea..94767d953 100644 --- a/source/local/local.go +++ b/source/local/local.go @@ -248,6 +248,10 @@ func getFeaturesFromHooks() (map[string]string, error) { for _, file := range files { fileName := file.Name() + // ignore hidden feature file + if strings.HasPrefix(fileName, ".") { + continue + } lines, err := runHook(fileName) if err != nil { klog.ErrorS(err, "failed to run hook", "fileName", fileName) @@ -324,6 +328,10 @@ func getFeaturesFromFiles() (map[string]string, error) { for _, file := range files { fileName := file.Name() + // ignore hidden feature file + if strings.HasPrefix(fileName, ".") { + continue + } lines, err := getFileContent(fileName) if err != nil { klog.ErrorS(err, "failed to read file", "fileName", fileName) diff --git a/source/local/testdata/features.d/.my.feature b/source/local/testdata/features.d/.my.feature new file mode 100644 index 000000000..e6cc8fa29 --- /dev/null +++ b/source/local/testdata/features.d/.my.feature @@ -0,0 +1 @@ +hiddenFeatureKey=hiddenFeatureValue