Skip to content

Commit

Permalink
Merge pull request #263 from autolab/hotfix_viewFeedback_archives
Browse files Browse the repository at this point in the history
Fixed Unrecognized Archive Type errors
  • Loading branch information
Ilter committed Feb 8, 2015
2 parents 63f7cdc + a44fe48 commit d027a56
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
3 changes: 3 additions & 0 deletions app/controllers/submissions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -485,11 +485,14 @@ def view

# Action to be taken when the user wants to get a listing of all
# files in a submission that is an archive file.
action_auth_level :listArchive, :student
def listArchive
begin
load_submission() or return false
get_submission_file() or return false

# note: @filename is defined by get_submission_file and is actually
# submission.handin_file_path because up is down and black is white.
archive_type = IO.popen(["file", "--brief", "--mime-type", @filename],
in: :close, err: :close) { |io| io.read.chomp }
@files = []
Expand Down
11 changes: 6 additions & 5 deletions app/models/submission.rb
Original file line number Diff line number Diff line change
Expand Up @@ -210,20 +210,21 @@ def get_filename_in_archive_at(position)
require 'zlib'
require 'zip'

archive_type = IO.popen(["file", "--brief", "--mime-type", self.filename],
filename = self.handin_file_path
archive_type = IO.popen(["file", "--brief", "--mime-type", filename],
in: :close, err: :close) { |io| io.read.chomp }
# Extract archive by type
if archive_type.include? "tar" then
f = File.new(self.filename)
f = File.new(filename)
archive_extract = Gem::Package::TarReader.new(f)
archive_extract.rewind # The extract has to be rewinded after every iteration
elsif archive_type.include? "gzip" then
archive_extract = Gem::Package::TarReader.new(Zlib::GzipReader.open self.filename)
archive_extract = Gem::Package::TarReader.new(Zlib::GzipReader.open filename)
archive_extract.rewind
elsif archive_type.include? "zip" then
archive_extract = Zip::File.open(self.filename)
archive_extract = Zip::File.open(filename)
else
raise "Unrecognized archive type!"
return self.filename # well, we tried
end

# Iterate through archive until file position
Expand Down

0 comments on commit d027a56

Please sign in to comment.