Explicitly copy folders before adding files

This allows to protect copied files while additionally allowing learners to add new files in copied subdirectories
This commit is contained in:
Sebastian Serth
2022-10-26 10:13:04 +02:00
committed by Sebastian Serth
parent 9e7b3b7b58
commit 9ea94ed4fc

View File

@ -111,7 +111,15 @@ class Runner::Strategy::Poseidon < Runner::Strategy
url = "#{runner_url}/files"
Rails.logger.debug { "#{Time.zone.now.getutc.inspect}: Sending files to #{url}" }
copy = files.map do |file|
# First create all the directories to apply the sticky bit for additional protection
# See https://github.com/openHPI/poseidon/pull/240
copy = files.uniq(&:path).filter_map do |file|
next if file.path.blank?
{path: "#{file.path}/"}
end
copy += files.map do |file|
{
path: file.filepath,
content: Base64.strict_encode64(file.read || ''),