diff --git a/lib/dav4rack/controller.rb b/lib/dav4rack/controller.rb index a042ec3a..2c352c3c 100644 --- a/lib/dav4rack/controller.rb +++ b/lib/dav4rack/controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'uri' require 'dav4rack/destination_header' require 'dav4rack/request' @@ -240,6 +242,7 @@ module DAV4Rack return MultiStatus end + properties = if propfind.nil? or propfind.empty? or propfind.xpath("//#{ns}allprop").first @@ -274,7 +277,6 @@ module DAV4Rack r.multistatus do |xml| xml << r.raw(prop_xml) end - MultiStatus end diff --git a/lib/dav4rack/file_resource_lock.rb b/lib/dav4rack/file_resource_lock.rb index 4cf65475..0421089a 100644 --- a/lib/dav4rack/file_resource_lock.rb +++ b/lib/dav4rack/file_resource_lock.rb @@ -106,7 +106,7 @@ module DAV4Rack end def remaining_timeout - t = timeout.to_i - (Time.current.to_i - created_at.to_i) + t = timeout.to_i - (Time.now.to_i - created_at.to_i) t < 0 ? 0 : t end @@ -116,7 +116,7 @@ module DAV4Rack :token => token, :timeout => timeout, :depth => depth, - :created_at => Time.current, + :created_at => Time.now, :owner => owner } @store.transaction do diff --git a/lib/dav4rack/handler.rb b/lib/dav4rack/handler.rb index d741bf50..ce67589a 100644 --- a/lib/dav4rack/handler.rb +++ b/lib/dav4rack/handler.rb @@ -24,11 +24,11 @@ module DAV4Rack end def call(env) - start = Time.current + start = Time.now request = setup_request env response = Rack::Response.new - Logger.info "Processing WebDAV request: #{request.path} (for #{request.ip} at #{Time.current}) [#{request.request_method}]" + Logger.info "Processing WebDAV request: #{request.path} (for #{request.ip} at #{Time.now}) [#{request.request_method}]" controller = setup_controller request, response controller.process @@ -41,7 +41,7 @@ module DAV4Rack if Logger.debug? and response.body.is_a?(String) Logger.debug "Response String:\n#{response.body}" end - Logger.info "Completed in: #{((Time.current.to_f - start.to_f) * 1000).to_i} ms | #{response.status} [#{request.url}]" + Logger.info "Completed in: #{((Time.now.to_f - start.to_f) * 1000).to_i} ms | #{response.status} [#{request.url}]" response.finish diff --git a/lib/dav4rack/interceptor_resource.rb b/lib/dav4rack/interceptor_resource.rb index a23b8e0b..00e502d3 100644 --- a/lib/dav4rack/interceptor_resource.rb +++ b/lib/dav4rack/interceptor_resource.rb @@ -25,15 +25,15 @@ module DAV4Rack end def creation_date - Time.current + Time.now end def last_modified - Time.current + Time.now end def last_modified=(time) - Time.current + Time.now end def etag diff --git a/lib/dav4rack/lock.rb b/lib/dav4rack/lock.rb index 58f2619f..e37c0d06 100644 --- a/lib/dav4rack/lock.rb +++ b/lib/dav4rack/lock.rb @@ -4,8 +4,8 @@ module DAV4Rack def initialize(args={}) @args = args @store = nil - @args[:created_at] = Time.current - @args[:updated_at] = Time.current + @args[:created_at] = Time.now + @args[:updated_at] = Time.now end def store @@ -24,7 +24,7 @@ module DAV4Rack end def remaining_timeout - @args[:timeout].to_i - (Time.current.to_i - @args[:created_at].to_i) + @args[:timeout].to_i - (Time.now.to_i - @args[:created_at].to_i) end def method_missing(*args) diff --git a/lib/dav4rack/remote_file.rb b/lib/dav4rack/remote_file.rb index d412c1ae..8bcbde7f 100644 --- a/lib/dav4rack/remote_file.rb +++ b/lib/dav4rack/remote_file.rb @@ -107,7 +107,7 @@ module DAV4Rack # Last modified type based on provided, remote headers or current time def last_modified - @heads['last-modified'] || @modified || Time.current.httpdate + @heads['last-modified'] || @modified || Time.now.httpdate end # Builds the path for the cached file diff --git a/lib/dav4rack/request.rb b/lib/dav4rack/request.rb index 3a867db7..709dee54 100644 --- a/lib/dav4rack/request.rb +++ b/lib/dav4rack/request.rb @@ -19,12 +19,16 @@ module DAV4Rack def initialize(env, options = {}) super env @options = { recursive_propfind_allowed: true }.merge options - sanitize_path_info + self.path_info = expand_path path_info end def authorization? - !!env['HTTP_AUTHORIZATION'] + !!authorization + end + + def authorization + get_header 'HTTP_AUTHORIZATION' end # path relative to root uri @@ -131,11 +135,15 @@ module DAV4Rack return uri.path_info end - # expands '/foo/../bar' to '/bar' + # expands '/foo/../bar' to '/bar', peserving trailing slash and normalizing + # consecutive slashes. adds a leading slash if missing def expand_path(path) - path.squeeze! '/' - path = Addressable::URI.normalize_component path, Addressable::URI::CharacterClasses::PATH - URI("http://example.com/").merge(path).path + path = path.squeeze '/' + path.prepend '/' unless path[0] == '/' + collection = path.end_with?('/') + path = ::File.expand_path path + path << '/' if collection and !path.end_with?('/') + path end @@ -181,10 +189,6 @@ module DAV4Rack request_method != 'PROPFIND' or @options[:recursive_propfind_allowed] end - def sanitize_path_info - self.path_info.force_encoding 'UTF-8' - self.path_info = expand_path path_info - end def parse_request_body return Nokogiri.XML(body.read){ |config| diff --git a/lib/dav4rack/resource.rb b/lib/dav4rack/resource.rb index 22e2bb65..58031d57 100644 --- a/lib/dav4rack/resource.rb +++ b/lib/dav4rack/resource.rb @@ -79,11 +79,11 @@ module DAV4Rack @namespaces = (options[:namespaces] || {}).merge({DAV_NAMESPACE => DAV_NAMESPACE_NAME}) @request = request @response = response - if (options.has_key?(:lock_class)) + unless(options.has_key?(:lock_class)) + @lock_class = LockStore + else @lock_class = options[:lock_class] raise NameError.new("Unknown lock type constant provided: #{@lock_class}") unless @lock_class.nil? || defined?(@lock_class) - else - @lock_class = LockStore end @options = options @max_timeout = options[:max_timeout] || 86400 diff --git a/lib/dav4rack/resources/file_resource.rb b/lib/dav4rack/resources/file_resource.rb index e20cb8d6..c48a26c8 100644 --- a/lib/dav4rack/resources/file_resource.rb +++ b/lib/dav4rack/resources/file_resource.rb @@ -42,7 +42,7 @@ module DAV4Rack # Set the time of last modification. def last_modified=(time) - ::File.utime(Time.current, time, file_path) + ::File.utime(Time.now, time, file_path) end # Return an Etag, an unique hash value for this resource. @@ -227,17 +227,19 @@ module DAV4Rack end def lock(args) - if (parent_exists?) + unless(parent_exists?) + Conflict + else lock_check(args[:type]) lock = FileResourceLock.explicit_locks(@path, root, :scope => args[:scope], :kind => args[:type], :user => @user) - unless (lock) + unless(lock) token = UUIDTools::UUID.random_create.to_s lock = FileResourceLock.generate(@path, @user, token, root) lock.scope = args[:scope] lock.kind = args[:type] lock.owner = args[:owner] lock.depth = args[:depth] - if (args[:timeout]) + if(args[:timeout]) lock.timeout = args[:timeout] <= @max_timeout && args[:timeout] > 0 ? args[:timeout] : @max_timeout else lock.timeout = @default_timeout @@ -253,8 +255,6 @@ module DAV4Rack status end [lock.remaining_timeout, lock.token] - else - Conflict end end diff --git a/lib/dav4rack/version.rb b/lib/dav4rack/version.rb index d386f6c5..9f4df790 100644 --- a/lib/dav4rack/version.rb +++ b/lib/dav4rack/version.rb @@ -13,5 +13,5 @@ module DAV4Rack end end - VERSION = Version.new('1.1.0') + VERSION = Version.new('1.1.1') end