Skip to content

Commit

Permalink
clean up symlink in the event of HTTP 500
Browse files Browse the repository at this point in the history
  • Loading branch information
cchou committed Nov 29, 2011
1 parent f259e2f commit 08691fb
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions describe.rb
Expand Up @@ -160,16 +160,10 @@ def get_config
throw :halt, [400, "invalid url location"] throw :halt, [400, "invalid url location"]
end end




# make sure the file exist and it's a valid file # make sure the file exist and it's a valid file
if (File.symlink?(@input) || File.file?(@input)) then if (File.symlink?(@input) || File.file?(@input)) then
description description
if io FileUtils.rm @input
io.unlink
else
FileUtils.rm link
end
else else
throw :halt, [404, "either #{@input} does not exist or it is not a valid file"] throw :halt, [404, "either #{@input} does not exist or it is not a valid file"]
end end
Expand Down Expand Up @@ -214,14 +208,19 @@ def get_config
@originalName = params['document'][:filename] @originalName = params['document'][:filename]
# describe the transmitted file with format identifier and metadata # describe the transmitted file with format identifier and metadata
description description
File.delete(@input) number = File.delete(@input)
puts "delete #{@input}, result #{number}"
response.finish response.finish
end end


get '/status' do get '/status' do
[ 200, {'Content-Type' => 'application/xml'}, "<status/>\n" ] [ 200, {'Content-Type' => 'application/xml'}, "<status/>\n" ]
end end


def cleanup
end

# perform format description and generate the result in premis
def description def description
jhove = RJhove.instance jhove = RJhove.instance
droid = RDroid.instance droid = RDroid.instance
Expand All @@ -242,7 +241,8 @@ def description
rescue => e rescue => e
Datyl::Logger.err "running into exception #{e} while processing #{@originalName}" Datyl::Logger.err "running into exception #{e} while processing #{@originalName}"
Datyl::Logger.err e.backtrace.join("\n") Datyl::Logger.err e.backtrace.join("\n")
throw :halt, [500, "running into exception #{e} while processing #{@originalName}\n#{e.backtrace.join('\n')}"] FileUtils.rm @input
throw :halt, [500, "running into exception #{e} while processing #{@originalName}\n#{e.backtrace.join('\n')}"]
end end


@formats.clear @formats.clear
Expand All @@ -258,6 +258,7 @@ def description
@result.clear @result.clear
@result = nil @result = nil
else else
FileUtils.rm @input
throw :halt, [500, "unexpected empty response while processing #{@originalName}"] throw :halt, [500, "unexpected empty response while processing #{@originalName}"]
end end


Expand Down

0 comments on commit 08691fb

Please sign in to comment.