Skip to content
This repository has been archived by the owner on Jan 11, 2023. It is now read-only.

Overwrite folder/file for performCOPY: #588

Open
fabiosoft opened this issue May 27, 2022 · 0 comments
Open

Overwrite folder/file for performCOPY: #588

fabiosoft opened this issue May 27, 2022 · 0 comments

Comments

@fabiosoft
Copy link

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant