cordova-plugin-file icon indicating copy to clipboard operation
cordova-plugin-file copied to clipboard

copyTo command doesn't follow spec that is linked to from the README

Open coulson84 opened this issue 4 years ago • 1 comments

Bug Report

Problem

On iOS, the copyTo command is throwing a path exists error when trying to call copyTo that overwrites an existing file

What is expected to happen?

According to the spec "A copy of a file on top of an existing file must attempt to delete and replace that file."

What does actually happen?

An error is thrown relating to the path existing so I assume that instead of trying to overwrite the file it is just bailing out

Information

https://www.w3.org/TR/2012/WD-file-system-api-20120417/#widl-Entry-copyTo-void-DirectoryEntry-parent-DOMString-newName-EntryCallback-successCallback-ErrorCallback-errorCallback

Command or Code

fileEntry.copyTo(targetDirectory, newName, successCallback, errorCallback);

Environment, Platform, Device

iOS 13.x any iOS device

Version information

cordova-plugin-file 6.0.2

Checklist

  • [x ] I searched for existing GitHub issues
  • [x ] I updated all Cordova tooling to most recent version
  • [ x] I included all the necessary information above

coulson84 avatar Jun 03 '20 14:06 coulson84

Exactly this is still happening for me, i.e. when running on iOS only, using FileEntry.copyTo() onto an existing file results in a PATH_EXISTS_ERR. Looking into the source code at plugins/cordova-plugin-file/src/iOS/CDVLocalFilesystem.m, in the copyFileToURL() routine, lines 493-495 are:

} else if (bNewExists) {
     // the full destination should NOT already exist if a copy
     errCode = PATH_EXISTS_ERR;

As @coulson84 notes above, the (now deprecated) standard at W3C says that copyTo() should delete an existing destination file before copying. Should this be followed in the source code above? Or perhaps the plugin's copyTo() routine should have an options argument that allows this?

It's not hard to work around-- on iOS, the app can just delete a destination file before copying-- but perhaps this could be fixed for the sake of consistency with other platforms, or at a minimum documented under "iOS Quirks".

jmarshall-com avatar Feb 06 '22 20:02 jmarshall-com