From 89a9bbbb2b3fb268614c641998f881a9681cf26a Mon Sep 17 00:00:00 2001 From: Raul E Rangel Date: Tue, 3 Jun 2014 15:27:02 -0600 Subject: [PATCH] Re-uploading existing file was failing The context_info contains a conflicts hash or a conflicts array depending on the number of conflicts. We should make sure we handle both cases correctly. --- lib/ruby-box/folder.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/ruby-box/folder.rb b/lib/ruby-box/folder.rb index 66908e6..e3f0e3b 100644 --- a/lib/ruby-box/folder.rb +++ b/lib/ruby-box/folder.rb @@ -34,10 +34,12 @@ def upload_file(filename, data, overwrite=true) # This is a workaround around: begin # were were given context information about this conflict? - file = RubyBox::File.new(@session, { - 'id' => e['context_info']['conflicts'][0]['id'] - }) - rescue + # conflicts an either be an array or a hash + if (context_info = e['context_info']) && (conflicts = context_info['conflicts']) && (conflict = [conflicts].flatten(1).first) && (id = conflict['id']) + file = RubyBox::File.new(@session, { + 'id' => id + }) + else # we were not given context information about this conflict. # attempt to lookup the file. file = files(filename, 1000).pop