Overwrite folder/file for performCOPY:
fabiosoft opened this issue · 0 comments
I'am using GCDWebDAVServer
method performCOPY:
, for copying files or folders.
Everything seems to work good, but when I try to overwrite a folder (already existing) setting the header field: Overwrite: T
I get copy error on line: 394
if (![[NSFileManager defaultManager] copyItemAtPath:srcAbsolutePath toPath:dstAbsolutePath error:&error]) {
return [GCDWebServerErrorResponse responseWithClientError:kGCDWebServerHTTPStatusCode_Forbidden underlyingError:error message:@"Failed copying \"%@\" to \"%@\"", srcRelativePath, dstRelativePath];
}
so it returns forbidden
error.
As stated in Apple documentation
If a file with the same name already exists at dstPath, this method stops the copy attempt and returns an appropriate error.
https://developer.apple.com/documentation/foundation/nsfilemanager/1407903-copyitematpath
I think before attempt the copy you should delete the destination folder if already exists, like you did for move method.
if (isMove) {
[[NSFileManager defaultManager] removeItemAtPath:dstAbsolutePath error:NULL];
if (![[NSFileManager defaultManager] moveItemAtPath:srcAbsolutePath toPath:dstAbsolutePath error:&error]) {
return [GCDWebServerErrorResponse responseWithClientError:kGCDWebServerHTTPStatusCode_Forbidden underlyingError:error message:@"Failed copying \"%@\" to \"%@\"", srcRelativePath, dstRelativePath];
}
} else {
Let me know if you have the same problem and how to solve, maybe (client side) I need to request a file delete, then retry the copy.