Use file name with file path as identifier

This commit is contained in:
Sebastian Serth
2021-12-15 00:43:42 +01:00
parent d543ac76ae
commit 0c1a10959c
11 changed files with 18 additions and 27 deletions

View File

@ -36,10 +36,10 @@ class CommunitySolutionsController < ApplicationController
# Add the ReadMe file first
@files += all_visible_files.select {|f| CodeOcean::File.find_by(id: f.file_id)&.context_type == 'CommunitySolution' }
# Then, add all remaining files and sort them by name with extension
@files += (all_visible_files - @files).sort_by(&:name_with_extension)
@files += (all_visible_files - @files).sort_by(&:filepath)
# Own Submission as a reference
@own_files = @submission.collect_files.select(&:visible).sort_by(&:name_with_extension)
@own_files = @submission.collect_files.select(&:visible).sort_by(&:filepath)
# Remove the file_id from the second graph. Otherwise, the comparison and file-tree selection does not work as expected
@own_files.map do |file|
file.file_id = nil

View File

@ -321,7 +321,7 @@ raise: false
@search = Search.new
@search.exercise = @exercise
@submission = current_user.submissions.where(exercise_id: @exercise.id).order('created_at DESC').first
@files = (@submission ? @submission.collect_files : @exercise.files).select(&:visible).sort_by(&:name_with_extension)
@files = (@submission ? @submission.collect_files : @exercise.files).select(&:visible).sort_by(&:filepath)
@paths = collect_paths(@files)
@user_id = if current_user.respond_to? :external_id

View File

@ -27,12 +27,7 @@ class SubmissionsController < ApplicationController
stringio = Zip::OutputStream.write_buffer do |zio|
@files.each do |file|
zio.put_next_entry(if file.path.to_s == ''
file.name_with_extension
else
File.join(file.path,
file.name_with_extension)
end)
zio.put_next_entry(file.filepath)
zio.write(file.content.presence || file.native_file.read)
end
@ -247,8 +242,7 @@ class SubmissionsController < ApplicationController
# parse remote request url
content += "#{request.base_url}/evaluate\n"
@submission.files.each do |file|
file_path = file.path.to_s == '' ? file.name_with_extension : File.join(file.path, file.name_with_extension)
content += "#{file_path}=#{file.file_id}\n"
content += "#{file.filepath}=#{file.file_id}\n"
end
File.open(path, 'w+') do |f|
f.write(content)
@ -317,7 +311,7 @@ class SubmissionsController < ApplicationController
# @files contains all visible files for the user
# @file contains the specific file requested for run / test / render / ...
set_files
@file = @files.detect {|file| file.name_with_extension == sanitize_filename }
@file = @files.detect {|file| file.filepath == sanitize_filename }
head :not_found unless @file
end

View File

@ -99,7 +99,7 @@ module CodeOcean
private :incomplete_descendent?
def name_with_extension
name + (file_type.file_extension || '')
name.to_s + (file_type&.file_extension || '')
end
def set_ancestor_values

View File

@ -160,7 +160,7 @@ class Submission < ApplicationRecord
# @raise [Runner::Error] if the code could not be run due to a failure with the runner.
# See the specific type and message for more details.
def run(file, &block)
run_command = command_for execution_environment.run_command, file.name_with_extension
run_command = command_for execution_environment.run_command, file.filepath
durations = {}
prepared_runner do |runner, waiting_duration|
durations[:execution_duration] = runner.attach_to_execution(run_command, &block)
@ -185,7 +185,7 @@ class Submission < ApplicationRecord
end
def run_test_file(file, runner, waiting_duration)
test_command = command_for execution_environment.test_command, file.name_with_extension
test_command = command_for execution_environment.test_command, file.filepath
result = {file_role: file.role, waiting_for_container_time: waiting_duration}
output = runner.execute_command(test_command, raise_exception: false)
result.merge(output)
@ -222,7 +222,7 @@ class Submission < ApplicationRecord
end
def command_for(template, file)
filepath = collect_files.find {|f| f.name_with_extension == file }.filepath
filepath = collect_files.find {|f| f.filepath == file }.filepath
template % command_substitutions(filepath)
end
@ -255,7 +255,7 @@ class Submission < ApplicationRecord
waiting_for_container_time: output[:waiting_for_container_time]
)
filename = file.name_with_extension
filename = file.filepath
if file.teacher_defined_linter?
LinterCheckRun.create_from(testrun, assessment)

View File

@ -1,3 +1,3 @@
# frozen_string_literal: true
json.extract! @file, :id, :name_with_extension
json.extract! @file, :id, :filepath

View File

@ -1,4 +1,4 @@
div class=(defined?(own_solution) ? "own-frame" : "frame") data-executable=file.file_type.executable? data-filename=file.name_with_extension data-renderable=file.file_type.renderable? data-role=file.role data-binary=file.file_type.binary? data-context-type=file.context_type data-read-only=file.read_only
div class=(defined?(own_solution) ? "own-frame" : "frame") data-executable=file.file_type.executable? data-filename=file.filepath data-renderable=file.file_type.renderable? data-role=file.role data-binary=file.file_type.binary? data-context-type=file.context_type data-read-only=file.read_only
- if file.file_type.binary?
.binary-file data-file-id=file.ancestor_id
- if file.file_type.renderable?

View File

@ -7,10 +7,7 @@ li.card.mt-2
a class=['file-heading', collapsed_class] data-toggle="collapse" href="#collapse#{f.index}" aria-expanded="#{aria_expanded}"
div.clearfix role="button"
i class="fa" aria-hidden="true"
- if f.object.name.present? && f.object.file_type.present?
span = f.object.name_with_extension
- else
span = f.object.name
span = f.object.filepath
.card-collapse.collapse class=('in' if f.object.name.nil?) id="collapse#{f.index}" role="tabpanel"
.card-body
- if policy(f.object).destroy? && id.present?

View File

@ -65,9 +65,9 @@ h1
td.align-middle
-this.testruns.includes(:file).order("files.name").each do |run|
- if run.passed
.unit-test-result.positive-result title=[run.file&.name_with_extension, run.output].join("\n").strip
.unit-test-result.positive-result title=[run.file&.filepath, run.output].join("\n").strip
- else
.unit-test-result.unknown-result title=[run.file&.name_with_extension, run.output].join("\n").strip
.unit-test-result.unknown-result title=[run.file&.filepath, run.output].join("\n").strip
td = @working_times_until[index] if index > 0 if policy(@exercise).detailed_statistics?
- elsif this.is_a? UserExerciseIntervention
td = this.created_at.strftime("%F %T")

View File

@ -49,7 +49,7 @@ ul.list-unstyled#files
a.file-heading.collapsed data-toggle="collapse" data-parent="#files" href=".collapse#{file.id}"
div.clearfix role="button"
i class="fa" aria-hidden="true"
span = file.name_with_extension
span = file.filepath
.card-collapse.collapse class="collapse#{file.id}" role="tabpanel"
.card-body
- if policy(file).destroy?

View File

@ -1,6 +1,6 @@
# frozen_string_literal: true
FILENAME_REGEXP = /[\w.]+/.freeze unless Kernel.const_defined?(:FILENAME_REGEXP)
FILENAME_REGEXP = %r{[\w./]+}.freeze unless Kernel.const_defined?(:FILENAME_REGEXP)
Rails.application.routes.draw do
resources :community_solutions, only: %i[index edit update]