@@ -46,45 +46,48 @@ def do_remote_file(source, path)
4646 # The current files checksum
4747 current_checksum = self . checksum ( path ) if ::File . exists? ( path )
4848
49- begin
50- # The remote filehandle
51- raw_file = get_from_uri ( source ) ||
52- get_from_server ( source , current_checksum ) ||
53- get_from_local_cookbook ( source )
54- rescue Net ::HTTPRetriableError => e
55- if e . response . kind_of? ( Net ::HTTPNotModified )
56- Chef ::Log . debug ( "File #{ path } is unchanged" )
57- return false
58- else
59- raise e
49+ unless ( @new_resource . checksum && @new_resource . checksum == current_checksum )
50+ begin
51+ # The remote filehandle
52+ raw_file = get_from_uri ( source ) ||
53+ get_from_server ( source , current_checksum ) ||
54+ get_from_local_cookbook ( source )
55+ rescue Net ::HTTPRetriableError => e
56+ if e . response . kind_of? ( Net ::HTTPNotModified )
57+ Chef ::Log . debug ( "File #{ path } is unchanged" )
58+ return false
59+ else
60+ raise e
61+ end
6062 end
61- end
6263
63- # If the file exists
64- if ::File . exists? ( @new_resource . path )
65- # And it matches the checksum of the raw file
66- @new_resource . checksum ( self . checksum ( raw_file . path ) )
67- if @new_resource . checksum != @current_resource . checksum
68- # Updating target file, let's perform a backup!
69- Chef ::Log . debug ( "#{ @new_resource } changed from #{ @current_resource . checksum } to #{ @new_resource . checksum } " )
70- Chef ::Log . info ( "Updating #{ @new_resource } at #{ @new_resource . path } " )
71- backup ( @new_resource . path )
64+ # If the file exists
65+ if ::File . exists? ( @new_resource . path )
66+ # And it matches the checksum of the raw file
67+ @new_resource . checksum ( self . checksum ( raw_file . path ) )
68+ if @new_resource . checksum != @current_resource . checksum
69+ # Updating target file, let's perform a backup!
70+ Chef ::Log . debug ( "#{ @new_resource } changed from #{ @current_resource . checksum } to #{ @new_resource . checksum } " )
71+ Chef ::Log . info ( "Updating #{ @new_resource } at #{ @new_resource . path } " )
72+ backup ( @new_resource . path )
73+ end
74+ else
75+ # We're creating a new file
76+ Chef ::Log . info ( "Creating #{ @new_resource } at #{ @new_resource . path } " )
7277 end
73- else
74- # We're creating a new file
75- Chef ::Log . info ( "Creating #{ @new_resource } at #{ @new_resource . path } " )
76- end
7778
78- FileUtils . cp ( raw_file . path , @new_resource . path )
79- @new_resource . updated = true
80-
79+ FileUtils . cp ( raw_file . path , @new_resource . path )
80+ @new_resource . updated = true
81+
82+ # We're done with the file, so make sure to close it if it was open.
83+ raw_file . close
84+ true
85+ end
86+
8187 set_owner if @new_resource . owner
8288 set_group if @new_resource . group
8389 set_mode if @new_resource . mode
8490
85- # We're done with the file, so make sure to close it if it was open.
86- raw_file . close
87- true
8891 end
8992
9093 def get_from_uri ( source )
0 commit comments