Skip to content

Commit

Permalink
Work with path strings internally (FIXME).
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian Aßmann committed Mar 31, 2011
1 parent c125520 commit dfb1c0e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
9 changes: 4 additions & 5 deletions lib/dav/resource/actions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ def put(responder, now = Time.now)
content_type &&= content_type.split(';').first
content_type ||= Rack::Mime.mime_type File.extname(uri.path)

properties.display_name = File.basename decoded_uri.path
properties.content_type = content_type
properties.display_name = File.basename decoded_uri.path
properties.content_type = content_type
end
properties.creation_date = now
properties.creation_date = now

responder.respond_to(uri) do |response|
response.on(:finish) { |status| store_all if status.ok? }
Expand All @@ -45,8 +45,7 @@ def delete(responder)
responder.respond_to uri do |response|
response.precondition do |condition|
success = children.uris.all? do |uri|
status = responder.status uri
status and status.ok?
status = responder.status(uri) and status.ok?
end
condition.failed_dependency! unless success
end
Expand Down
32 changes: 17 additions & 15 deletions lib/dav/resource/children.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class Children < Struct.new(:parent)
include DAV

SEPARATOR = "\n"
FINDER = "^[a-z]+:\/\/[^\/]+%s#{ SEPARATOR }"
FINDER = "^%s#{ SEPARATOR }"

def initialize(parent)
super parent
Expand All @@ -32,48 +32,50 @@ def store
end

def add(child)
@adds << child
@adds << child.decoded_uri.path
self
end
def remove(child)
@removes << child
@removes << child.decoded_uri.path
self
end

def include?(resource)
uris.include? parent.uri.join(resource.decoded_uri)
paths.include? resource.decoded_uri.path
end

def each
if block_given?
uris.each { |uri| yield parent.join(uri.path) }
paths.each { |path| yield parent.join(path) }
else
Enumerator.new self, :each
end
end

def uris
str = get_data
base = parent.uri

Set.new str.split(SEPARATOR).map { |uri| base.join URI.parse(uri).path }
paths.map { |path| base.join path }
end

protected

def get_data
relation_storage.get(parent.id) || ''
end
def paths
collection = get_data.split SEPARATOR
collection.pop

collection
end
def update(data)
unless @removes.empty?
paths = @removes.map { |child| Regexp.escape child.decoded_uri.path }
data.gsub!(/#{ FINDER % "(?:#{ paths.join '|' })" }/, '')
esc_paths = @removes.map { |path| Regexp.escape path }
data.gsub!(/#{ FINDER % "(?:#{ esc_paths.join '|' })" }/, '')
end

@adds.each do |child|
decoded_uri = child.decoded_uri
data =~ /#{ FINDER % Regexp.escape(decoded_uri.path) }/ or
data << "#{ decoded_uri }#{ SEPARATOR }"
@adds.each do |path|
next if data =~ /#{ FINDER % Regexp.escape(path) }/
data << "#{ path }\n"
end

unless data.empty?
Expand Down

0 comments on commit dfb1c0e

Please sign in to comment.