From 7cee335e13e2bd61d6e5f8f487791dc9cd6c89ab Mon Sep 17 00:00:00 2001 From: Karel Picman Date: Wed, 31 Jan 2018 14:13:39 +0100 Subject: [PATCH] #716 dav4rack -> planio/dav4rack --- lib/redmine_dmsf/webdav/custom_middleware.rb | 33 ++++++++++---------- lib/redmine_dmsf/webdav/dmsf_resource.rb | 5 +-- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/lib/redmine_dmsf/webdav/custom_middleware.rb b/lib/redmine_dmsf/webdav/custom_middleware.rb index e60d0fd1..b764042c 100644 --- a/lib/redmine_dmsf/webdav/custom_middleware.rb +++ b/lib/redmine_dmsf/webdav/custom_middleware.rb @@ -42,24 +42,23 @@ module RedmineDmsf def call(env) begin status, headers, body = @dav_app.call env - # If the URL map generated by Rack::Builder did not find a matching path, - # it will return a 404 along with the X-Cascade header set to 'pass'. - if status == 404 and headers['X-Cascade'] == 'pass' - # The MS web redirector webdav client likes to go up a level and try - # OPTIONS there. We catch that here and respond telling it that just - # plain HTTP is going on. - if 'OPTIONS'.casecmp(env['REQUEST_METHOD'].to_s) == 0 - [ '200', { 'Allow' => 'OPTIONS,HEAD,GET,PUT,POST,DELETE' }, [''] ] - else - # let Rails handle the request - @rails_app.call env - end - else - [status, headers, body] - end rescue Exception => e - # let Rails handle the request - @rails_app.call env + Rails.logger.error e.message + end + # If the URL map generated by Rack::Builder did not find a matching path, + # it will return a 404 along with the X-Cascade header set to 'pass'. + if status == 404 and headers['X-Cascade'] == 'pass' + # The MS web redirector webdav client likes to go up a level and try + # OPTIONS there. We catch that here and respond telling it that just + # plain HTTP is going on. + if 'OPTIONS'.casecmp(env['REQUEST_METHOD'].to_s) == 0 + [ '200', { 'Allow' => 'OPTIONS,HEAD,GET,PUT,POST,DELETE' }, [''] ] + else + # let Rails handle the request + @rails_app.call env + end + else + [status, headers, body] end end diff --git a/lib/redmine_dmsf/webdav/dmsf_resource.rb b/lib/redmine_dmsf/webdav/dmsf_resource.rb index 01ff776f..e42411ba 100644 --- a/lib/redmine_dmsf/webdav/dmsf_resource.rb +++ b/lib/redmine_dmsf/webdav/dmsf_resource.rb @@ -662,7 +662,8 @@ module RedmineDmsf # implementation of service for request, which allows for us to pipe a single file through # also best-utilising DAV4Rack's implementation. def download - raise NotFound unless (file && file.last_revision && file.last_revision.disk_file(false)) + disk_file = file.last_revision.disk_file + raise NotFound unless (file && file.last_revision && disk_file && File.exist?(disk_file)) raise Forbidden unless (!parent.exist? || !parent.folder || DmsfFolder.permissions?(parent.folder)) # If there is no range (start of ranged download, or direct download) then we log the # file access, so we can properly keep logged information @@ -673,7 +674,7 @@ module RedmineDmsf access.action = DmsfFileRevisionAccess::DownloadAction access.save! end - File.new(file.last_revision.disk_file) + File.new disk_file end private