Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set file modified time to value reported by wayback machine #220

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/wayback_machine_downloader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
require 'fileutils'
require 'cgi'
require 'json'
require 'time'
require_relative 'wayback_machine_downloader/tidy_bytes'
require_relative 'wayback_machine_downloader/to_regex'
require_relative 'wayback_machine_downloader/archive_api'
Expand Down Expand Up @@ -249,6 +250,7 @@ def download_file file_remote_info
file_id = file_remote_info[:file_id]
file_timestamp = file_remote_info[:timestamp]
file_path_elements = file_id.split('/')
original_file_mtime = nil
if file_id == ""
dir_path = backup_path
file_path = backup_path + 'index.html'
Expand All @@ -270,6 +272,9 @@ def download_file file_remote_info
begin
URI("https://web.archive.org/web/#{file_timestamp}id_/#{file_url}").open("Accept-Encoding" => "plain") do |uri|
file.write(uri.read)
if uri.meta.has_key?("x-archive-orig-last-modified")
original_file_mtime = Time.parse(uri.meta["x-archive-orig-last-modified"])
end
end
rescue OpenURI::HTTPError => e
puts "#{file_url} # #{e}"
Expand All @@ -281,6 +286,9 @@ def download_file file_remote_info
puts "#{file_url} # #{e}"
end
end
if not original_file_mtime.nil?
File.utime(File.atime(file_path), original_file_mtime, file_path)
end
rescue StandardError => e
puts "#{file_url} # #{e}"
ensure
Expand Down