phonegap / phonegap-plugin-contentsync

Download and cache remotely hosted content
Apache License 2.0
206 stars 98 forks source link

[iOS] copyRootApp runs a second time on the second launch of the application, overwriting updates #186

Closed blefebvre closed 6 years ago

blefebvre commented 6 years ago

Expected Behaviour

The copyRootApp operation should not overwrite any content in the sync'd directory on subsequent runs of the app, assuming the app's version has not increased.

Actual Behaviour

On the second run of an app that calls .sync() with copyRootApp: true set on startup, the copyRootApp operation will be performed again unnecessarily, effectively overwriting any changes that were made in the sync'd directory during the first run of the app.

Reproduce Scenario (including but not limited to)

This issue can be reproduced with this basic app repository: https://github.com/blefebvre/phonegap-plugin-contentsync-bugs

It has been reproduced successfully on iOS 11.1, 10.3, and 10.2.

Steps to Reproduce

  1. clone this repo: https://github.com/blefebvre/phonegap-plugin-contentsync-bugs
  2. prepare the iOS platform: phonegap prepare ios
  3. open the iOS project in Xcode: open platforms/ios/helloworld.xcworkspace/
  4. run the app from Xcode.
  5. the first time you run the app you will notice (in the logs) that it performs the copyRootApp operation. check for the text "Copying Root App" in the Xcode console.
  6. run the app again from Xcode.
  7. check again for the text "Copying Root App". a few lines above it, note the result of the version check that is being done:
    2017-11-09 16:31:49.340750-0500 helloworld[10506:522159] previous version (null)
    2017-11-09 16:31:49.340873-0500 helloworld[10506:522159] current version 1.0.5
    2017-11-09 16:31:49.341759-0500 helloworld[10506:522159] current version is newer than previous version
  8. since 1.0.5 (in my app's case) is considered to be "higher" than null, the copyRootApp operation will be performed again.

Platform and Version (eg. Android 5.0 or iOS 9.2.1)

Tested on iOS 11.1, 10.3, and 10.2. Not an issue on Android.

(Android) What device vendor (e.g. Samsung, HTC, Sony...)

n/a

Cordova CLI version and cordova platform version

phonegap -v: 7.1.1

phonegap platform version ios: 4.3.1

Plugin version

phonegap-plugin-contentsync 1.4.0 "content-sync"

Sample Code that illustrates the problem

https://github.com/blefebvre/phonegap-plugin-contentsync-bugs

Logs taken while reproducing problem

Included above.

macdonst commented 6 years ago

@blefebvre can you try this branch to see if it fixes your problem?

https://github.com/phonegap/phonegap-plugin-contentsync/pull/169

macdonst commented 6 years ago

@blefebvre this might be a duplicate of #166

blefebvre commented 6 years ago

@macdonst looks to me like the code in #169 is already in master (68b70d).

blefebvre commented 6 years ago

I should have mentioned that on run 3 (and beyond) of the app, this issue does not occur since the previousVersion has been set at this point (via hasAppBeenUpdated()), so the comparison works as expected:

2017-11-09 16:53:46.663171-0500 helloworld[11217:617981] previous version 1.0.5
2017-11-09 16:53:46.663258-0500 helloworld[11217:617981] current version 1.0.5
blefebvre commented 6 years ago

Fixed in 1.4.1