Skip to content

Commit

Permalink
Windows throws when trying to mv a Tempfile. Copy it instead
Browse files Browse the repository at this point in the history
  • Loading branch information
jazzido committed Feb 20, 2018
1 parent 34f2adc commit 40e1d05
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/tabula_workspace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ def move_file(path, document_id, filename)
FileUtils.mv(path, File.join(get_document_dir(document_id), filename))
end


def copy_file(path, document_id, filename)
FileUtils.cp_r(path, File.join(get_document_dir(document_id), filename))
end

def list_templates
read_workspace!
Expand Down
7 changes: 6 additions & 1 deletion webapp/tabula_web.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,12 @@ def upload(file)
file_id = Digest::SHA1.hexdigest(Time.now.to_s + original_filename) # just SHA1 of time isn't unique with multiple uploads
file_path = File.join(TabulaSettings::DOCUMENTS_BASEPATH, file_id)

Tabula::Workspace.instance.move_file(file[:tempfile].path, file_id, 'document.pdf')
begin
Tabula::Workspace.instance.move_file(file[:tempfile].path, file_id, 'document.pdf')
rescue Errno::EACCES
# Windows doesn't like tempfiles to be moved
Tabula::Workspace.instance.copy_file(file[:tempfile].path, file_id, 'document.pdf')
end

filepath = Tabula::Workspace.instance.get_document_path(file_id)
job_batch = SecureRandom.uuid
Expand Down

0 comments on commit 40e1d05

Please sign in to comment.