You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cordova.apache.org by "ASF GitHub Bot (JIRA)" <ji...@apache.org> on 2017/07/20 13:14:00 UTC

[jira] [Commented] (CB-6938) iOS File plugin: copyTo for file returns error when destination file exists

    [ https://issues.apache.org/jira/browse/CB-6938?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16094659#comment-16094659 ] 

ASF GitHub Bot commented on CB-6938:
------------------------------------

GitHub user VinceOPS opened a pull request:

    https://github.com/apache/cordova-plugin-file/pull/211

    CB-6938: (fix) on iOS, copyTo should overwrite any existing file

    https://issues.apache.org/jira/browse/CB-6938
    
    ### Platforms affected
    iOS, all versions.
    
    ### What does this PR do?
    It fixes CB-6938.
    Instead of returning an error 12 (PATH_EXISTS_ERR), it tries to remove the existing file, then to copy the "new" one.
    
    ### What testing has been done on this change?
    Simulator: iPhone 5 and iPhone 6 @ iOS 9, 10.
    Real device: iPhone 5 @ iOS 10.
    
    No unit test provided nor written.
    
    ### Checklist
    - [X] [Reported an issue](http://cordova.apache.org/contribute/issues.html) in the JIRA database
    - [X] Commit message follows the format: "CB-3232: (android) Fix bug with resolving file paths", where CB-xxxx is the JIRA ID & "android" is the platform affected.
    - [X] Added automated test coverage as appropriate for this change.


You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/VinceOPS/cordova-plugin-file CB-6938cordova-plugin-file

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/cordova-plugin-file/pull/211.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #211
    
----
commit 064c7f33e8d9b5dcee4f520e80a385336c9fcbc5
Author: VinceOPS <vi...@gmail.com>
Date:   2017-07-20T13:00:42Z

    iOS: (fix) copyTo should overwrite any existing file

----


> iOS File plugin: copyTo for file returns error when destination file exists
> ---------------------------------------------------------------------------
>
>                 Key: CB-6938
>                 URL: https://issues.apache.org/jira/browse/CB-6938
>             Project: Apache Cordova
>          Issue Type: Bug
>          Components: cordova-plugin-file
>    Affects Versions: 3.5.0
>         Environment: ios
>            Reporter: vldmrrrr
>            Assignee: Ian Clelland
>              Labels: iOS
>
> According to w3c spec:
> A copy of a file on top of an existing file must attempt to delete and replace that file.
> iOS version of plugin in file CDVLocalFilesystem.m contains this code for the case:
> {code}
>                 } else if (bNewExists) {
>                     // the full destination should NOT already exist if a copy
>                     errCode = PATH_EXISTS_ERR;
> {code}
> Suggested patch:
> {code}
> diff --git a/src/ios/CDVLocalFilesystem.m b/src/ios/CDVLocalFilesystem.m
> index d1576ad..f5aa508 100644
> --- a/src/ios/CDVLocalFilesystem.m
> +++ b/src/ios/CDVLocalFilesystem.m
> @@ -535,11 +535,11 @@
>                  if (bSrcIsDir && ![self canCopyMoveSrc:srcFullPath ToDestination:newFileSystemPath]) {
>                      // can't copy dir into self
>                      errCode = INVALID_MODIFICATION_ERR;
> -                } else if (bNewExists) {
> -                    // the full destination should NOT already exist if a copy
> -                    errCode = PATH_EXISTS_ERR;
>                  } else {
> -                    bSuccess = [fileMgr copyItemAtPath:srcFullPath toPath:newFileSystemPath error:&error];
> +                   bSuccess = YES;
> +                    if (bNewExists)
> +                        bSuccess = [fileMgr removeItemAtPath:newFileSystemPath error:&error];
> +                    if (bSuccess)
> +                        bSuccess = [fileMgr copyItemAtPath:srcFullPath toPath:newFileSystemPath error:&error];
>                  }
>              } else { // move
>                  // iOS requires that destination must not exist before calling moveTo
> {code}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org