From 3b1bcbe86eb53261371b584b6655f409f80ead1b Mon Sep 17 00:00:00 2001 From: Saku Ytti Date: Sun, 28 Aug 2016 13:23:52 +0300 Subject: expand_path in file output so that ``` output: file: directory: ~/foox ``` will work --- lib/oxidized/output/file.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/oxidized/output/file.rb') diff --git a/lib/oxidized/output/file.rb b/lib/oxidized/output/file.rb index bb13827..0b64447 100644 --- a/lib/oxidized/output/file.rb +++ b/lib/oxidized/output/file.rb @@ -17,7 +17,7 @@ class OxidizedFile < Output end def store node, outputs, opt={} - file = @cfg.directory + file = File.expand_path @cfg.directory if opt[:group] file = File.join File.dirname(file), opt[:group] end @@ -28,7 +28,7 @@ class OxidizedFile < Output end def fetch node, group - cfg_dir = @cfg.directory + cfg_dir = File.expand_path @cfg.directory if group # group is explicitly defined by user IO.readlines File.join(cfg_dir, group, node) else -- cgit v1.2.1 From 699136c8c3a1a409a2eaa19019ec6df6bb4b61e0 Mon Sep 17 00:00:00 2001 From: Danilo Sousa Date: Mon, 29 Aug 2016 16:42:06 -0300 Subject: fix the node variable from `#fetch`. closes #529 in commit `de2a9d1` I changed the `#fetch` method to pass the `Node` object instead of the node name. --- lib/oxidized/output/file.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'lib/oxidized/output/file.rb') diff --git a/lib/oxidized/output/file.rb b/lib/oxidized/output/file.rb index 0b64447..851e4c5 100644 --- a/lib/oxidized/output/file.rb +++ b/lib/oxidized/output/file.rb @@ -29,13 +29,15 @@ class OxidizedFile < Output def fetch node, group cfg_dir = File.expand_path @cfg.directory + node_name = node.name + if group # group is explicitly defined by user - IO.readlines File.join(cfg_dir, group, node) + IO.readlines File.join(cfg_dir, group, node_name) else - if File.exists? File.join(cfg_dir, node) # node configuration file is stored on base directory - IO.readlines File.join(cfg_dir, node) + if File.exists? File.join(cfg_dir, node_name) # node configuration file is stored on base directory + IO.readlines File.join(cfg_dir, node_name) else - path = Dir.glob File.join(cfg_dir, '**', node) # fetch node in all groups + path = Dir.glob File.join(cfg_dir, '**', node_name) # fetch node in all groups return nil if path[0].nil? open(path[0], 'r').readlines end -- cgit v1.2.1 From 449522554473f4b9a261ec06ee6961defb30f7bb Mon Sep 17 00:00:00 2001 From: Saku Ytti Date: Wed, 26 Oct 2016 13:32:01 +0300 Subject: fetch should return string, not array Also if group was explicitly given, we referred to wrong directory --- lib/oxidized/output/file.rb | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'lib/oxidized/output/file.rb') diff --git a/lib/oxidized/output/file.rb b/lib/oxidized/output/file.rb index 851e4c5..78db1d5 100644 --- a/lib/oxidized/output/file.rb +++ b/lib/oxidized/output/file.rb @@ -28,18 +28,19 @@ class OxidizedFile < Output end def fetch node, group - cfg_dir = File.expand_path @cfg.directory + cfg_dir = File.expand_path @cfg.directory node_name = node.name if group # group is explicitly defined by user - IO.readlines File.join(cfg_dir, group, node_name) + cfg_dir = File.join File.dirname(cfg_dir), group + File.read File.join(cfg_dir, node_name) else if File.exists? File.join(cfg_dir, node_name) # node configuration file is stored on base directory - IO.readlines File.join(cfg_dir, node_name) + File.read File.join(cfg_dir, node_name) else - path = Dir.glob File.join(cfg_dir, '**', node_name) # fetch node in all groups - return nil if path[0].nil? - open(path[0], 'r').readlines + path = Dir.glob(File.join(cfg_dir, '**', node_name)).first # fetch node in all groups + return nil if not path + File.read path end end end -- cgit v1.2.1 From 9ce9133dbf4589786329d5dad239f80882ea07ea Mon Sep 17 00:00:00 2001 From: Saku Ytti Date: Wed, 26 Oct 2016 22:08:19 +0300 Subject: return nil if we can't find file unsure if we really should, or just raise the error and let consumer of fetch decide what to do with the error --- lib/oxidized/output/file.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib/oxidized/output/file.rb') diff --git a/lib/oxidized/output/file.rb b/lib/oxidized/output/file.rb index 78db1d5..5327a80 100644 --- a/lib/oxidized/output/file.rb +++ b/lib/oxidized/output/file.rb @@ -39,10 +39,11 @@ class OxidizedFile < Output File.read File.join(cfg_dir, node_name) else path = Dir.glob(File.join(cfg_dir, '**', node_name)).first # fetch node in all groups - return nil if not path File.read path end end + rescue Errno::ENOENT + return nil end def version node, group -- cgit v1.2.1 From 8dbd596ed73ff9d9cbe68093372fee799b6fd482 Mon Sep 17 00:00:00 2001 From: Saku Ytti Date: Mon, 12 Dec 2016 11:54:33 +0200 Subject: Recursively search from one dir above specified Fixes #626 --- lib/oxidized/output/file.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/oxidized/output/file.rb') diff --git a/lib/oxidized/output/file.rb b/lib/oxidized/output/file.rb index 5327a80..45f72e1 100644 --- a/lib/oxidized/output/file.rb +++ b/lib/oxidized/output/file.rb @@ -38,7 +38,7 @@ class OxidizedFile < Output if File.exists? File.join(cfg_dir, node_name) # node configuration file is stored on base directory File.read File.join(cfg_dir, node_name) else - path = Dir.glob(File.join(cfg_dir, '**', node_name)).first # fetch node in all groups + path = Dir.glob(File.join(File.dirname(cfg_dir), '**', node_name)).first # fetch node in all groups File.read path end end -- cgit v1.2.1