From e22c1015c5b59264d6a6c8333cb6b185596b9f40 Mon Sep 17 00:00:00 2001 From: Ken Case Date: Wed, 8 Apr 2015 13:29:23 -0700 Subject: [PATCH] Updated WebDAV support to pass OmniPresence's conformance tests for COPY and MOVE: * COPY no longer fails when a Depth isn't specified. (According to RFC2518, the COPY method on a collection without a Depth header MUST act as if a Depth header with value "infinity" was included.) * MOVE and COPY no longer fail when a file exists at the destination path and Overwrite isn't set to false. --- Extensions/WebDAV/DAVResponse.m | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/Extensions/WebDAV/DAVResponse.m b/Extensions/WebDAV/DAVResponse.m index 7bd69ace..eb264377 100644 --- a/Extensions/WebDAV/DAVResponse.m +++ b/Extensions/WebDAV/DAVResponse.m @@ -183,9 +183,12 @@ - (id) initWithMethod:(NSString*)method headers:(NSDictionary*)headers bodyData: // 9.8 COPY Method // 9.9 MOVE Method if ([method isEqualToString:@"MOVE"] || [method isEqualToString:@"COPY"]) { - if ([method isEqualToString:@"COPY"] && ![[headers objectForKey:@"Depth"] isEqualToString:@"infinity"]) { - HTTPLogError(@"Unsupported DAV depth \"%@\"", [headers objectForKey:@"Depth"]); - return nil; + if ([method isEqualToString:@"COPY"]) { + NSString *depth = [headers objectForKey:@"Depth"]; + if (depth != nil && ![depth isEqualToString:@"infinity"]) { // The COPY method on a collection without a Depth header MUST act as if a Depth header with value "infinity" was included + HTTPLogError(@"Unsupported DAV depth \"%@\"", [headers objectForKey:@"Depth"]); + return nil; + } } NSString* sourcePath = [rootPath stringByAppendingPathComponent:resourcePath]; @@ -200,7 +203,7 @@ - (id) initWithMethod:(NSString*)method headers:(NSDictionary*)headers bodyData: } NSString* destinationPath = [rootPath stringByAppendingPathComponent: [[destination substringFromIndex:(range.location + range.length)] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; - if (![destinationPath hasPrefix:rootPath] || [[NSFileManager defaultManager] fileExistsAtPath:destinationPath]) { + if (![destinationPath hasPrefix:rootPath]) { return nil; } @@ -210,10 +213,14 @@ - (id) initWithMethod:(NSString*)method headers:(NSDictionary*)headers bodyData: _status = 409; } else { BOOL existing = [[NSFileManager defaultManager] fileExistsAtPath:destinationPath]; - if (existing && [[headers objectForKey:@"Overwrite"] isEqualToString:@"F"]) { + BOOL shouldNotOverwrite = [[headers objectForKey:@"Overwrite"] isEqualToString:@"F"]; + if (existing && shouldNotOverwrite) { HTTPLogError(@"Pre-existing destination path \"%@\"", destinationPath); _status = 412; } else { + if (existing && !shouldNotOverwrite) { + [[NSFileManager defaultManager] removeItemAtPath:destinationPath error:NULL]; + } if ([method isEqualToString:@"COPY"]) { if ([[NSFileManager defaultManager] copyItemAtPath:sourcePath toPath:destinationPath error:NULL]) { _status = existing ? 204 : 201;