From 067d158b977b8d756fa8d3c7d3c708f35f5532c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Pi=C4=8Dman?= Date: Wed, 16 Sep 2015 12:01:18 +0200 Subject: [PATCH] Webdav: Filter Mac OS X 'resource forks' Files #54 --- app/models/dmsf_file.rb | 6 +----- lib/redmine_dmsf/webdav/dmsf_resource.rb | 11 +++++++---- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/app/models/dmsf_file.rb b/app/models/dmsf_file.rb index 5f3e8b7a..6c535dae 100644 --- a/app/models/dmsf_file.rb +++ b/app/models/dmsf_file.rb @@ -406,9 +406,5 @@ class DmsfFile < ActiveRecord::Base def image? self.last_revision && !!(self.last_revision.disk_filename =~ /\.(bmp|gif|jpg|jpe|jpeg|png)$/i) end - - def exist? - return self.last_revision && File.exist?(self.last_revision.disk_file) - end - + end \ No newline at end of file diff --git a/lib/redmine_dmsf/webdav/dmsf_resource.rb b/lib/redmine_dmsf/webdav/dmsf_resource.rb index 4a77152b..fa84f36a 100644 --- a/lib/redmine_dmsf/webdav/dmsf_resource.rb +++ b/lib/redmine_dmsf/webdav/dmsf_resource.rb @@ -179,7 +179,7 @@ module RedmineDmsf def etag filesize = file ? file.size : 4096; - fileino = (file && file.last_revision) ? File.stat(file.last_revision.disk_file).ino : 2; + fileino = (file && file.last_revision && File.exist?(file.last_revision.disk_file)) ? File.stat(file.last_revision.disk_file).ino : 2; sprintf('%x-%x-%x', fileino, filesize, last_modified.to_i) end @@ -488,7 +488,7 @@ module RedmineDmsf raise Forbidden unless User.current.admin? || User.current.allowed_to?(:file_manipulation, project) # Ignore Mac OS X resource forks and special Windows files. - if basename.match(/^\._/i) || basename.match(/^ThumbsT.db$/i) + if basename.match(/^\._/i) || basename.match(/^Thumbs.db$/i) Rails.logger.info "#{basename} ignored" return NoContent end @@ -538,7 +538,7 @@ module RedmineDmsf # Ignore Mac OS X resource forks and special Windows files. unless request.body.length > 0 Rails.logger.info "#{basename} #{request.body.length}b ignored" - return NoContent + return Created end raise InternalServerError unless new_revision.valid? && f.save @@ -560,6 +560,9 @@ module RedmineDmsf # for lock information to be presented def get_property(element) raise NotImplemented if (element[:ns_href] != 'DAV:') + unless folder? + return NotFound unless (file && file.last_revision && File.exist?(file.last_revision.disk_file)) + end case element[:name] when 'supportedlock' then supported_lock when 'lockdiscovery' then discover_lock @@ -580,7 +583,7 @@ 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 + raise NotFound unless (file && file.last_revision && file.last_revision.disk_file) # 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