22require 'fileutils'
33require 'tempfile'
44
5+ SEPARATOR = [ Regexp . escape ( File ::SEPARATOR . to_s ) , Regexp . escape ( File ::ALT_SEPARATOR . to_s ) ] . join
6+
57Puppet ::Reports . register_report ( :store ) do
68 desc "Store the yaml report on disk. Each host sends its report as a YAML dump
79 and this just stores the file on disk, in the `reportdir` directory.
1315 def process
1416 # We don't want any tracking back in the fs. Unlikely, but there
1517 # you go.
16- client = self . host . gsub ( ".." , "." )
18+ if host =~ Regexp . union ( /[#{ SEPARATOR } ]/ , /\A \. \. ?\Z / )
19+ raise ArgumentError , "Invalid node name #{ host . inspect } "
20+ end
1721
18- dir = File . join ( Puppet [ :reportdir ] , client )
22+ dir = File . join ( Puppet [ :reportdir ] , host )
1923
2024 if ! FileTest . exists? ( dir )
2125 FileUtils . mkdir_p ( dir )
@@ -42,17 +46,20 @@ def process
4246 FileUtils . mv ( f . path , file )
4347 rescue => detail
4448 puts detail . backtrace if Puppet [ :trace ]
45- Puppet . warning "Could not write report for #{ client } at #{ file } : #{ detail } "
49+ Puppet . warning "Could not write report for #{ host } at #{ file } : #{ detail } "
4650 end
4751
4852 # Only testing cares about the return value
4953 file
5054 end
5155
52- # removes all reports for a given host
56+ # removes all reports for a given host?
5357 def self . destroy ( host )
54- client = host . gsub ( ".." , "." )
55- dir = File . join ( Puppet [ :reportdir ] , client )
58+ if host =~ Regexp . union ( /[#{ SEPARATOR } ]/ , /\A \. \. ?\Z / )
59+ raise ArgumentError , "Invalid node name #{ host . inspect } "
60+ end
61+
62+ dir = File . join ( Puppet [ :reportdir ] , host )
5663
5764 if File . exists? ( dir )
5865 Dir . entries ( dir ) . each do |file |
0 commit comments