app/controllers/concerns/deposit_data.rb
# given a file chunk and a relative path, write it to the correct place in the temporary deposit
given a file chunk and a relative path, write it to the correct place in the temporary deposit
given a file chunk and a relative path write it to the correct place in the temporary deposit
def write_deposit_chunk (filechunk, path, dataset_id, size, write_mode)
    upload_dir = File.join(@temp_upload_dir, dataset_id, "objects") 
    target_file = sanitise_path(File.join(upload_dir, path))
    target_dir = File.dirname(target_file)
    FileUtils.mkdir_p(target_dir)
    validate_deposit_chunk(filechunk, target_file, upload_dir, dataset_id, write_mode)
    File.open(target_file, write_mode) do |file|
      file.write(filechunk)
    end
    if (File.size(target_file).to_i == size.to_i and File.extname(target_file) == '.zip') then
      begin
        Zip::File.open(target_file) do |zip_file|
          zip_file.each do |entry|
            unless entry.name.include?("__MACOSX") then
              newpath = File.join(File.dirname(target_file), File.basename(target_file, File.extname(target_file)))
              FileUtils.mkdir_p(newpath)
              entry.extract(File.join(newpath, sanitise_path(entry.name)))
            end
          end
        end
        File.delete(target_file)
      rescue
      end
    end
  end
def write_deposit_chunk ( filechunk , path , dataset_id , size , write_mode ) upload_dir = File . join ( @temp_upload_dir , dataset_id , "objects" ) target_file = sanitise_path ( File . join ( upload_dir , path ) ) target_dir = File . dirname ( target_file ) FileUtils . mkdir_p ( target_dir ) validate_deposit_chunk ( filechunk , target_file , upload_dir , dataset_id , write_mode ) File . open ( target_file , write_mode ) do | file | file . write ( filechunk ) end if ( File . size ( target_file ) . to_i == size . to_i and File . extname ( target_file ) == '.zip' ) then begin Zip :: File . open ( target_file ) do | zip_file | zip_file . each do | entry | unless entry . name . include? ( "__MACOSX" ) then newpath = File . join ( File . dirname ( target_file ) , File . basename ( target_file , File . extname ( target_file ) ) ) FileUtils . mkdir_p ( newpath ) entry . extract ( File . join ( newpath , sanitise_path ( entry . name ) ) ) end end end File . delete ( target_file ) rescue end end end
given a file chunk and a relative path, write it to the correct place in the temporary deposit
given a file chunk and a relative path write it to the correct place in the temporary deposit
# work out the base folder into which this file should go # work out where to write it - it'll need to go in the temp upload directory for now, and it might have its own relative path # validate that deposited chunk is OK # if we've finished writing the file and it's a zip file, unzip it # extract everything except mac osx guff into a folder with the base-name of the zip file # delete zip file after extracting # don't do anything about bad zips
filechunk
<not_specific>
path
<not_specific>
dataset_id
<not_specific>
size
<not_specific>
write_mode
<not_specific>