From 828a58b9e3c8ca5da310d0d1750c4001100b3a69 Mon Sep 17 00:00:00 2001 From: Cody Cutrer Date: Thu, 4 Aug 2011 12:32:50 -0600 Subject: [PATCH] don't fail zipping empty folders. fixes #5002 Change-Id: I510facebfc85fd617013741d862d3417b66ce341 Reviewed-on: https://gerrit.instructure.com/4949 Reviewed-by: Brian Palmer Tested-by: Hudson --- lib/content_zipper.rb | 6 ++---- spec/lib/content_zipper_spec.rb | 12 ++++++++++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/content_zipper.rb b/lib/content_zipper.rb index f3a5d8c170e..7d252b4233e 100644 --- a/lib/content_zipper.rb +++ b/lib/content_zipper.rb @@ -225,7 +225,7 @@ class ContentZipper end def zip_base_folder(zip_attachment, folder) - @files_added = false + @files_added = true @logger.debug("zipping into attachment: #{zip_attachment.id}") zip_attachment.workflow_state = 'zipping' #!(:workflow_state => 'zipping') zip_attachment.scribd_attempts += 1 @@ -285,9 +285,7 @@ class ContentZipper @context = folder.context @logger.debug(" found attachment: #{attachment.unencoded_filename}") path = folder_names.empty? ? attachment.filename : File.join(folder_names, attachment.unencoded_filename) - if add_attachment_to_zip(attachment, zipfile, path) - @files_added = true - end + @files_added = false unless add_attachment_to_zip(attachment, zipfile, path) end folder.active_sub_folders.select{|f| !@user || f.grants_right?(@user, nil, :read_contents)}.each do |sub_folder| new_names = Array.new(folder_names) << sub_folder.name diff --git a/spec/lib/content_zipper_spec.rb b/spec/lib/content_zipper_spec.rb index c9e621e1b45..e00c46b42a4 100644 --- a/spec/lib/content_zipper_spec.rb +++ b/spec/lib/content_zipper_spec.rb @@ -47,5 +47,17 @@ describe ContentZipper do end names.sort.should == ['visible.png', 'visible/sub-vis.png'] end + + it "should not error on empty folders" do + course_with_student(:active_all => true) + folder = Folder.root_folders(@course).first + attachment = Attachment.new(:display_name => 'my_download.zip') + attachment.user_id = @user.id + attachment.workflow_state = 'to_be_zipped' + attachment.context = folder + attachment.save! + ContentZipper.process_attachment(attachment, @user) + attachment.workflow_state.should == 'zipped' + end end end