From 064c7f33e8d9b5dcee4f520e80a385336c9fcbc5 Mon Sep 17 00:00:00 2001 From: VinceOPS Date: Thu, 20 Jul 2017 15:00:42 +0200 Subject: [PATCH] iOS: (fix) copyTo should overwrite any existing file --- src/ios/CDVLocalFilesystem.m | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/ios/CDVLocalFilesystem.m b/src/ios/CDVLocalFilesystem.m index c340ce0cc..3436af686 100644 --- a/src/ios/CDVLocalFilesystem.m +++ b/src/ios/CDVLocalFilesystem.m @@ -551,8 +551,13 @@ - (void)copyFileToURL:(CDVFilesystemURL *)destURL withName:(NSString *)newName f // 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; + // first try to remove the existing file + bSuccess = [fileMgr removeItemAtPath:newFileSystemPath error:&error]; + + if (bSuccess) { + // then copy the new one + bSuccess = [fileMgr copyItemAtPath:srcFullPath toPath:newFileSystemPath error:&error]; + } } else { bSuccess = [fileMgr copyItemAtPath:srcFullPath toPath:newFileSystemPath error:&error]; }