Skip to content

Instantly share code, notes, and snippets.

@xuru
Created September 28, 2012 18:56
Show Gist options
  • Select an option

  • Save xuru/3801533 to your computer and use it in GitHub Desktop.

Select an option

Save xuru/3801533 to your computer and use it in GitHub Desktop.
has_remote_file_modified: Ruby method to examine the http header and see if a file is newer on the remote system
class Chef
class Recipe
def has_remote_file_modified(uri, filepath)
require 'net/http'
http = Net::HTTP.new(uri.host, uri.port)
req = Net::HTTP::Head.new(uri.path)
if uri.user
req.basic_auth uri.user, uri.password
end
resp = http.request(req).to_hash
server_date = Time.httpdate(resp['last-modified'].first)
file_date = File.mtime(filepath)
file_date < server_date
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment