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

Overwrite folder/file for performCOPY: #588

Description

@fabiosoft

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions