14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/async/caldav/handlers/move.rb', line 14
def call(path:, storage:, headers: {}, **)
destination = ['destination']
return [400, { 'content-type' => 'text/plain' }, ['Missing Destination header']] unless destination
to_path = URI.parse(destination).path
overwrite = ['overwrite'] != 'F'
source = storage.get_item(path.to_s)
return [404, { 'content-type' => 'text/plain' }, ['Not Found']] unless source
existing = storage.get_item(to_path)
if existing && !overwrite
return [412, { 'content-type' => 'text/plain' }, ['Precondition Failed']]
end
if !existing
uid = (source[:body])
if uid
dest_col = Protocol::Caldav::Path.new(to_path).parent.to_s
items = storage.list_items(dest_col)
items.each do |item_path, item_data|
next if item_path == path.to_s
if (item_data[:body]) == uid
return [409, { 'content-type' => 'text/plain' }, ['UID conflict']]
end
end
end
end
storage.move_item(path.to_s, to_path)
if existing
[204, {}, ['']]
else
[201, {}, ['']]
end
end
|