phonegap / phonegap-plugin-contentsync

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

[iOS] - Requesting an resource with the same id does not replace the resource by default #156

Closed bhellema closed 7 years ago

bhellema commented 7 years ago

According to the options.type documentation the default behaviour is to delete the old content and cache the new content. On iOS this does not seem to be the case.

Using the following call:

var sync = ContentSync.sync({
      id: 'image.png', 
      src: url
});

results in:

image

From the logs:

2016-12-07 14:50:51.711 OAuth Sample[44341:4529015] Moving /Users/b/Library/Developer/CoreSimulator/Devices/153B23AC-E56D-4F16-81A8-21BD766CA4D0/data/Containers/Data/Application/6EF22B32-EF85-47D2-96B0-1228CAF0608F/Library/image to /Users/b/Library/Developer/CoreSimulator/Devices/153B23AC-E56D-4F16-81A8-21BD766CA4D0/data/Containers/Data/Application/6EF22B32-EF85-47D2-96B0-1228CAF0608F/Library/image.png
2016-12-07 14:50:51.711 OAuth Sample[44341:4529020] Task: /Users/b/Library/Developer/CoreSimulator/Devices/153B23AC-E56D-4F16-81A8-21BD766CA4D0/data/Containers/Data/Application/6EF22B32-EF85-47D2-96B0-1228CAF0608F/Library/image.png completed successfully
imhotep commented 7 years ago

What does the URL look like?

macdonst commented 7 years ago

@bhellema check out the latest code from master and let me know if it fixes your issue.

@imhotep can you give the latest commit a once over?

imhotep commented 7 years ago

@macdonst I would also check for the type just to be safe and move it to line 402 before this if statement.

NSString* type = [sTask.command argumentAtIndex:2 withDefault:@"replace"];
if([fileManager fileExistsAtPath:[dstURL path]] && replace == YES) {
    NSLog(@"%@ already exists. Deleting it since type is set to `replace`", [dstURL path]);
    [fileManager removeItemAtURL:dstURL error:NULL];
}

I would also remove this code as it would be a duplicate.

bhellema commented 7 years ago

@macdonst the latest src looks like it has resolved issue.

👍