app/controllers/concerns/deposit_data.rb
# check that the uploaded chunk is valid
check that the uploaded chunk is valid
check that the uploaded chunk is valid
def validate_deposit_chunk (filechunk, target_file, upload_dir, dataset_id, write_mode)
    dataset = find_dataset(dataset_id)
    upload_size = (`du -bs #{upload_dir} | tail -n 1 | cut -f 1`).to_i
    if dataset.aips.size > 0
      raise "Files have already been deposited for this dataset"
    elsif File.basename(target_file).length > 254 or target_file.length > 4095
      raise "File name or file path is too long"
    elsif upload_size + filechunk.size > MAX_UPLOAD_BYTES
      raise "Upload is too large - exceeds maximum upload size"
    elsif write_mode == "wb" and File.exists?(target_file)
      raise "The file already exists"
    elsif !(current_user and current_user.email and (current_user.admin? or (dataset.creator_string and dataset.creator_string.include? current_user.email.split("@")[0])))
      raise "User is not allowed to deposit files for this dataset"
    end
  end
def validate_deposit_chunk ( filechunk , target_file , upload_dir , dataset_id , write_mode ) dataset = find_dataset ( dataset_id ) upload_size = ( ` du -bs  #{ upload_dir }  | tail -n 1 | cut -f 1 ` ) . to_i if dataset . aips . size > 0 raise "Files have already been deposited for this dataset" elsif File . basename ( target_file ) . length > 254 or target_file . length > 4095 raise "File name or file path is too long" elsif upload_size + filechunk . size > MAX_UPLOAD_BYTES raise "Upload is too large - exceeds maximum upload size" elsif write_mode == "wb" and File . exists? ( target_file ) raise "The file already exists" elsif ! ( current_user and current_user . email and ( current_user . admin? or ( dataset . creator_string and dataset . creator_string . include? current_user . email . split ( "@" ) [ 0 ] ) ) ) raise "User is not allowed to deposit files for this dataset" end end
check that the uploaded chunk is valid
check that the uploaded chunk is valid
#Rails.logger.debug("Upload size is #{upload_size.to_s} bytes") # it's a problem if this dataset isn't accepting uploads # it's a problem if the filename > 254 chars or the path > 4095 chars # it's a problem if the size of the files already written plus the size of this chunk exceed the max upload size # it's a problem if this is a new file and the file already exists # it's a problem if the remote user isn't a valid depositor
filechunk
<not_specific>
target_file
<not_specific>
upload_dir
<not_specific>
dataset_id
<not_specific>
write_mode
<not_specific>