Created
September 28, 2012 18:56
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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