11
12
13
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
|
# File 'lib/async/caldav/handlers/move.rb', line 11
def call(path:, storage:, headers: {}, **)
destination = ['destination']
if destination
to_path = URI.parse(destination).path
overwrite = ['overwrite'] != 'F'
source = storage.get_item(path.to_s)
if source
existing = storage.get_item(to_path)
if existing && !overwrite
[412, { 'content-type' => 'text/plain' }, ['Precondition Failed']]
elsif !existing && uid_conflict?(
path,
to_path,
source[:body],
storage,
)
[409, { 'content-type' => 'text/plain' }, ['UID conflict']]
else
storage.move_item(path.to_s, to_path)
if existing
[204, {}, ['']]
else
[201, {}, ['']]
end
end
else
[404, { 'content-type' => 'text/plain' }, ['Not Found']]
end
else
[400, { 'content-type' => 'text/plain' }, ['Missing Destination header']]
end
end
|