From b81c6950f2a2d70cc1047c76da5f3b02a491b544 Mon Sep 17 00:00:00 2001 From: hartator Date: Thu, 10 Sep 2015 00:35:48 -0500 Subject: [PATCH] Handle different Errno::EEXIST exceptions from different ruby versions --- lib/wayback_machine_downloader.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/wayback_machine_downloader.rb b/lib/wayback_machine_downloader.rb index c62efb9..1b9a719 100644 --- a/lib/wayback_machine_downloader.rb +++ b/lib/wayback_machine_downloader.rb @@ -109,8 +109,15 @@ class WaybackMachineDownloader begin FileUtils::mkdir_p dir_path unless File.exists? dir_path rescue Errno::EEXIST => e - puts "# #{e}" - file_already_existing = e.to_s.split("File exists - ")[-1] + error_to_string = e.to_s + puts "# #{error_to_string}" + if error_to_string.include? "File exists @ dir_s_mkdir - " + file_already_existing = e.to_s.split("File exists @ dir_s_mkdir - ")[-1] + elsif error_to_string.include? "File exists - " + file_already_existing = e.to_s.split("File exists - ")[-1] + else + raise "Unhandled directory restructure # #{error_to_string}" + end file_already_existing_temporary = file_already_existing + '.temp' file_already_existing_permanent = file_already_existing + '/index.html' FileUtils::mv file_already_existing, file_already_existing_temporary