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

Fix student download submission bug to have unique names #2244

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
17 changes: 17 additions & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,30 @@ def download_all_submissions

temp_file = Tempfile.new("autolab_submissions.zip")
Zip::File.open(temp_file.path, Zip::File::CREATE) do |zipfile|
# track counts of each file name
track_duplicate_counts = Hash.new(0)
submissions.each do |s|
entry_name = download_filename(s.handin_file_path, s.assessment.name)
track_duplicate_counts[entry_name] += 1
end

# track which version is being processed (for naming purposes)
filename_counts = Hash.new(0)
submissions.each do |s|
p = s.handin_file_path
course_name = s.course_user_datum.course.name
assignment_name = s.assessment.name
course_directory = "#{filename}/#{course_name}"
assignment_directory = "#{course_directory}/#{assignment_name}"
entry_name = download_filename(p, assignment_name)
filename_counts[entry_name] += 1
# append version number to submission if more than one of same name
if track_duplicate_counts[entry_name] > 1
version_suffix = "_ver#{filename_counts[entry_name]}"
extname = File.extname(entry_name)
basename = File.basename(entry_name, extname)
entry_name = "#{basename}#{version_suffix}#{extname}"
end
zipfile.add(File.join(assignment_directory, entry_name), p)
end
end
Expand Down