Revision 3812626f pithos-macos/PithosSyncDaemon.m
b/pithos-macos/PithosSyncDaemon.m | ||
---|---|---|
62 | 62 |
object:(ASIPithosObject *)object |
63 | 63 |
localFilePath:(NSString *)filePath; |
64 | 64 |
- (void)requestFailed:(ASIPithosRequest *)request; |
65 |
|
|
66 |
- (void)increaseSyncOperationCount; |
|
67 |
- (void)decreaseSyncOperationCount; |
|
68 |
|
|
65 | 69 |
@end |
66 | 70 |
|
67 | 71 |
@implementation PithosSyncDaemon |
68 |
@synthesize blockHash, blockSize, lastModified, remoteObjects, storedLocalObjectStates; |
|
72 |
@synthesize blockHash, blockSize, lastModified, lastCompletedSync, remoteObjects, storedLocalObjectStates;
|
|
69 | 73 |
@synthesize pithosStateFilePath, tempDownloadsDirPath; |
70 | 74 |
|
71 | 75 |
#pragma mark - |
... | ... | |
120 | 124 |
[storedLocalObjectStates release]; |
121 | 125 |
[remoteObjects release]; |
122 | 126 |
[objects release]; |
127 |
[lastCompletedSync release]; |
|
123 | 128 |
[lastModified release]; |
124 | 129 |
[blockHash release]; |
125 | 130 |
[containerName release]; |
... | ... | |
189 | 194 |
[data writeToFile:self.pithosStateFilePath atomically:YES]; |
190 | 195 |
} |
191 | 196 |
|
197 |
- (void)increaseSyncOperationCount { |
|
198 |
@synchronized(self) { |
|
199 |
syncOperationCount++; |
|
200 |
} |
|
201 |
} |
|
202 |
|
|
203 |
- (void)decreaseSyncOperationCount { |
|
204 |
@synchronized(self) { |
|
205 |
syncOperationCount--; |
|
206 |
if (!syncOperationCount && !syncIncomplete) { |
|
207 |
self.lastCompletedSync = [NSDate date]; |
|
208 |
[activityFacility startAndEndActivityWithType:PithosActivityOther |
|
209 |
message:[NSString stringWithFormat:@"Sync: Completed %@", lastCompletedSync]]; |
|
210 |
} |
|
211 |
} |
|
212 |
} |
|
213 |
|
|
192 | 214 |
- (void)sync { |
193 | 215 |
@synchronized(self) { |
194 | 216 |
if (syncOperationCount) { |
... | ... | |
199 | 221 |
// The first operation is the server listing |
200 | 222 |
syncOperationCount = 1; |
201 | 223 |
newSyncRequested = NO; |
224 |
syncIncomplete = NO; |
|
202 | 225 |
} |
203 | 226 |
} |
204 | 227 |
|
... | ... | |
244 | 267 |
message:@"Sync: Getting server listing"]; |
245 | 268 |
containerRequest.userInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys: |
246 | 269 |
activity, @"activity", |
270 |
@"Sync: Getting server listing (stopped)", @"stoppedActivityMessage", |
|
271 |
@"Sync: Getting server listing (failed)", @"failedActivityMessage", |
|
272 |
@"Sync: Getting server listing (finished)", @"finishedActivityMessage", |
|
273 |
[NSNumber numberWithInteger:NSOperationQueuePriorityVeryHigh], @"priority", |
|
247 | 274 |
[NSNumber numberWithUnsignedInteger:10], @"retries", |
248 | 275 |
nil]; |
249 |
// [[PithosUtilities prepareRequest:containerRequest priority:NSOperationQueuePriorityVeryHigh] startAsynchronous]; |
|
250 | 276 |
[queue addOperation:[PithosUtilities prepareRequest:containerRequest priority:NSOperationQueuePriorityVeryHigh]]; |
251 | 277 |
} |
252 | 278 |
|
... | ... | |
400 | 426 |
message:[NSString stringWithFormat:@"Sync: Downloading '%@' (100%%)", object.name]]; |
401 | 427 |
} else if (storedState.tmpDownloadFile == nil) { |
402 | 428 |
// Create new local object |
403 |
@synchronized(self) { |
|
404 |
syncOperationCount++; |
|
405 |
} |
|
429 |
[self increaseSyncOperationCount]; |
|
406 | 430 |
__block ASIPithosObjectRequest *objectRequest = [PithosUtilities objectBlockDataRequestWithContainerName:containerName |
407 | 431 |
object:object |
408 | 432 |
blockIndex:0 |
... | ... | |
423 | 447 |
[NSString stringWithFormat:@"Sync: Downloading '%@' (stopped)", object.name], @"stoppedActivityMessage", |
424 | 448 |
[NSString stringWithFormat:@"Sync: Downloading '%@' (failed)", object.name], @"failedActivityMessage", |
425 | 449 |
[NSString stringWithFormat:@"Sync: Downloading '%@' (100%%)", object.name], @"finishedActivityMessage", |
426 |
[NSNumber numberWithInteger:NSOperationQueuePriorityHigh], @"priority",
|
|
450 |
[NSNumber numberWithInteger:NSOperationQueuePriorityNormal], @"priority",
|
|
427 | 451 |
[NSNumber numberWithUnsignedInteger:10], @"retries", |
428 | 452 |
nil]; |
429 | 453 |
[objectRequest setBytesReceivedBlock:^(unsigned long long size, unsigned long long total){ |
... | ... | |
434 | 458 |
totalBytes:activity.totalBytes |
435 | 459 |
currentBytes:(activity.currentBytes + size)]; |
436 | 460 |
}]; |
437 |
// [[PithosUtilities prepareRequest:objectRequest priority:NSOperationQueuePriorityHigh] startAsynchronous]; |
|
438 |
[queue addOperation:[PithosUtilities prepareRequest:objectRequest priority:NSOperationQueuePriorityHigh]]; |
|
461 |
[queue addOperation:[PithosUtilities prepareRequest:objectRequest priority:NSOperationQueuePriorityNormal]]; |
|
439 | 462 |
} else { |
440 | 463 |
// Resume local object download |
441 |
@synchronized(self) { |
|
442 |
syncOperationCount++; |
|
443 |
} |
|
464 |
[self increaseSyncOperationCount]; |
|
444 | 465 |
ASIPithosObjectRequest *objectRequest = [ASIPithosObjectRequest objectHashmapRequestWithContainerName:containerName |
445 | 466 |
objectName:object.name]; |
446 | 467 |
objectRequest.delegate = self; |
... | ... | |
458 | 479 |
[NSString stringWithFormat:@"Sync: Downloading '%@' (stopped)", object.name], @"stoppedActivityMessage", |
459 | 480 |
[NSString stringWithFormat:@"Sync: Downloading '%@' (failed)", object.name], @"failedActivityMessage", |
460 | 481 |
[NSString stringWithFormat:@"Sync: Downloading '%@' (100%%)", object.name], @"finishedActivityMessage", |
461 |
[NSNumber numberWithInteger:NSOperationQueuePriorityHigh], @"priority",
|
|
482 |
[NSNumber numberWithInteger:NSOperationQueuePriorityNormal], @"priority",
|
|
462 | 483 |
[NSNumber numberWithUnsignedInteger:10], @"retries", |
463 | 484 |
nil]; |
464 |
// [[PithosUtilities prepareRequest:objectRequest priority:NSOperationQueuePriorityHigh] startAsynchronous]; |
|
465 |
[queue addOperation:[PithosUtilities prepareRequest:objectRequest priority:NSOperationQueuePriorityHigh]]; |
|
485 |
[queue addOperation:[PithosUtilities prepareRequest:objectRequest priority:NSOperationQueuePriorityNormal]]; |
|
466 | 486 |
} |
467 | 487 |
} |
468 | 488 |
|
469 | 489 |
-(void)updateServerStateWithCurrentState:(PithosLocalObjectState *)currentState |
470 | 490 |
object:(ASIPithosObject *)object |
471 | 491 |
localFilePath:(NSString *)filePath { |
492 |
[self increaseSyncOperationCount]; |
|
472 | 493 |
if (currentState.isDirectory) { |
473 | 494 |
// Create remote directory object |
474 |
@synchronized(self) { |
|
475 |
syncOperationCount++; |
|
476 |
} |
|
477 | 495 |
ASIPithosObjectRequest *objectRequest = [ASIPithosObjectRequest writeObjectDataRequestWithContainerName:containerName |
478 | 496 |
objectName:object.name |
479 | 497 |
eTag:nil |
... | ... | |
499 | 517 |
[NSNumber numberWithInteger:NSOperationQueuePriorityHigh], @"priority", |
500 | 518 |
[NSNumber numberWithUnsignedInteger:10], @"retries", |
501 | 519 |
nil]; |
502 |
// [[PithosUtilities prepareRequest:objectRequest priority:NSOperationQueuePriorityHigh] startAsynchronous]; |
|
503 | 520 |
[queue addOperation:[PithosUtilities prepareRequest:objectRequest priority:NSOperationQueuePriorityHigh]]; |
504 | 521 |
} else if ([currentState.md5 isEqualToString:@" "] && [currentState.hashMapHash isEqualToString:@" "]) { |
505 | 522 |
// Delete remote object |
506 |
@synchronized(self) { |
|
507 |
syncOperationCount++; |
|
523 |
NSString *safeObjectName = [PithosUtilities safeObjectNameForContainerName:@"trash" |
|
524 |
objectName:object.name]; |
|
525 |
if (safeObjectName) { |
|
526 |
ASIPithosObjectRequest *objectRequest = [PithosUtilities moveObjectRequestWithContainerName:containerName |
|
527 |
objectName:object.name |
|
528 |
destinationContainerName:@"trash" |
|
529 |
destinationObjectName:safeObjectName |
|
530 |
checkIfExists:NO]; |
|
531 |
if (objectRequest) { |
|
532 |
objectRequest.delegate = self; |
|
533 |
objectRequest.didFinishSelector = @selector(moveObjectToTrashFinished:); |
|
534 |
objectRequest.didFailSelector = @selector(requestFailed:); |
|
535 |
PithosActivity *activity = [activityFacility startActivityWithType:PithosActivityDelete |
|
536 |
message:[NSString stringWithFormat:@"Sync: Moving to trash '%@'", object.name]]; |
|
537 |
objectRequest.userInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys: |
|
538 |
object, @"pithosObject", |
|
539 |
activity, @"activity", |
|
540 |
[NSString stringWithFormat:@"Sync: Moving to trash '%@' (stopped)", object.name], @"stoppedActivityMessage", |
|
541 |
[NSString stringWithFormat:@"Sync: Moving to trash '%@' (failed)", object.name], @"failedActivityMessage", |
|
542 |
[NSString stringWithFormat:@"Sync: Moving to trash '%@' (finished)", object.name], @"finishedActivityMessage", |
|
543 |
[NSNumber numberWithInteger:NSOperationQueuePriorityHigh], @"priority", |
|
544 |
[NSNumber numberWithUnsignedInteger:10], @"retries", |
|
545 |
nil]; |
|
546 |
[queue addOperation:[PithosUtilities prepareRequest:objectRequest priority:NSOperationQueuePriorityHigh]]; |
|
547 |
} else { |
|
548 |
syncIncomplete = YES; |
|
549 |
[self decreaseSyncOperationCount]; |
|
550 |
} |
|
551 |
} else { |
|
552 |
syncIncomplete = YES; |
|
553 |
[self decreaseSyncOperationCount]; |
|
508 | 554 |
} |
509 |
ASIPithosObjectRequest *objectRequest = [ASIPithosObjectRequest deleteObjectRequestWithContainerName:containerName |
|
510 |
objectName:object.name]; |
|
511 |
objectRequest.delegate = self; |
|
512 |
objectRequest.didFinishSelector = @selector(deleteObjectFinished:); |
|
513 |
objectRequest.didFailSelector = @selector(requestFailed:); |
|
514 |
PithosActivity *activity = [activityFacility startActivityWithType:PithosActivityDelete |
|
515 |
message:[NSString stringWithFormat:@"Sync: Deleting '%@'", object.name]]; |
|
516 |
objectRequest.userInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys: |
|
517 |
object, @"pithosObject", |
|
518 |
activity, @"activity", |
|
519 |
[NSString stringWithFormat:@"Sync: Deleting '%@' (stopped)", object.name], @"stoppedActivityMessage", |
|
520 |
[NSString stringWithFormat:@"Sync: Deleting '%@' (failed)", object.name], @"failedActivityMessage", |
|
521 |
[NSString stringWithFormat:@"Sync: Deleting '%@' (finished)", object.name], @"finishedActivityMessage", |
|
522 |
[NSNumber numberWithInteger:NSOperationQueuePriorityHigh], @"priority", |
|
523 |
[NSNumber numberWithUnsignedInteger:10], @"retries", |
|
524 |
nil]; |
|
525 |
// [[PithosUtilities prepareRequest:objectRequest priority:NSOperationQueuePriorityHigh] startAsynchronous]; |
|
526 |
[queue addOperation:[PithosUtilities prepareRequest:objectRequest priority:NSOperationQueuePriorityHigh]]; |
|
527 | 555 |
} else { |
528 | 556 |
// Upload file to remote object |
529 | 557 |
NSError *error = nil; |
... | ... | |
543 | 571 |
hashes:&hashes |
544 | 572 |
sharingAccount:nil]; |
545 | 573 |
if (objectRequest) { |
546 |
@synchronized(self) { |
|
547 |
syncOperationCount++; |
|
548 |
} |
|
549 | 574 |
objectRequest.delegate = self; |
550 | 575 |
objectRequest.didFinishSelector = @selector(uploadObjectUsingHashMapFinished:); |
551 | 576 |
objectRequest.didFailSelector = @selector(requestFailed:); |
... | ... | |
563 | 588 |
[NSString stringWithFormat:@"Sync: Uploading '%@' (stopped)", object.name], @"stoppedActivityMessage", |
564 | 589 |
[NSString stringWithFormat:@"Sync: Uploading '%@' (failed)", object.name], @"failedActivityMessage", |
565 | 590 |
[NSString stringWithFormat:@"Sync: Uploading '%@' (100%%)", object.name], @"finishedActivityMessage", |
566 |
[NSNumber numberWithInteger:NSOperationQueuePriorityHigh], @"priority",
|
|
591 |
[NSNumber numberWithInteger:NSOperationQueuePriorityNormal], @"priority",
|
|
567 | 592 |
[NSNumber numberWithUnsignedInteger:10], @"retries", |
568 | 593 |
nil]]; |
569 |
// [[PithosUtilities prepareRequest:objectRequest priority:NSOperationQueuePriorityHigh] startAsynchronous]; |
|
570 |
[queue addOperation:[PithosUtilities prepareRequest:objectRequest priority:NSOperationQueuePriorityHigh]]; |
|
594 |
[queue addOperation:[PithosUtilities prepareRequest:objectRequest priority:NSOperationQueuePriorityNormal]]; |
|
595 |
} else { |
|
596 |
syncIncomplete = YES; |
|
597 |
[self decreaseSyncOperationCount]; |
|
571 | 598 |
} |
572 | 599 |
} |
573 | 600 |
|
... | ... | |
613 | 640 |
newContainerRequest.didFailSelector = @selector(listRequestFailed:); |
614 | 641 |
newContainerRequest.userInfo = newContainerRequest.userInfo; |
615 | 642 |
[(NSMutableDictionary *)newContainerRequest.userInfo setObject:[NSNumber numberWithUnsignedInteger:10] forKey:@"retries"]; |
616 |
// [[PithosUtilities prepareRequest:newContainerRequest priority:NSOperationQueuePriorityVeryHigh] startAsynchronous]; |
|
617 |
[queue addOperation:[PithosUtilities prepareRequest:newContainerRequest priority:NSOperationQueuePriorityHigh]]; |
|
643 |
[queue addOperation:[PithosUtilities prepareRequest:newContainerRequest priority:[[newContainerRequest.userInfo objectForKey:@"priority"] integerValue]]]; |
|
618 | 644 |
return; |
619 | 645 |
} |
620 | 646 |
} |
621 | 647 |
[activityFacility endActivity:[containerRequest.userInfo objectForKey:@"activity"] |
622 |
withMessage:@"Sync: Getting server listing (finished)"];
|
|
648 |
withMessage:[containerRequest.userInfo objectForKey:@"finishedActivityMessage"]];
|
|
623 | 649 |
NSFileManager *fileManager = [NSFileManager defaultManager]; |
624 | 650 |
NSString *containerDirectoryPath = [directoryPath stringByAppendingPathComponent:containerName]; |
625 | 651 |
NSError *error = nil; |
... | ... | |
769 | 795 |
} |
770 | 796 |
} |
771 | 797 |
@synchronized(self) { |
772 |
syncOperationCount--;
|
|
798 |
[self decreaseSyncOperationCount];
|
|
773 | 799 |
if (newSyncRequested && !syncOperationCount) |
774 | 800 |
[self sync]; |
775 | 801 |
} |
... | ... | |
778 | 804 |
if (retries > 0) { |
779 | 805 |
ASIPithosContainerRequest *newContainerRequest = (ASIPithosContainerRequest *)[PithosUtilities copyRequest:containerRequest]; |
780 | 806 |
[(NSMutableDictionary *)(newContainerRequest.userInfo)setObject:[NSNumber numberWithUnsignedInteger:(--retries)] forKey:@"retries"]; |
781 |
// [[PithosUtilities prepareRequest:newContainerRequest priority:NSOperationQueuePriorityVeryHigh] startAsynchronous]; |
|
782 |
[queue addOperation:[PithosUtilities prepareRequest:newContainerRequest priority:NSOperationQueuePriorityHigh]]; |
|
807 |
[queue addOperation:[PithosUtilities prepareRequest:newContainerRequest priority:[[newContainerRequest.userInfo objectForKey:@"priority"] integerValue]]]; |
|
783 | 808 |
} else { |
784 | 809 |
[activityFacility endActivity:[containerRequest.userInfo objectForKey:@"activity"] |
785 |
withMessage:@"Sync: Getting server listing (failed)"];
|
|
810 |
withMessage:[containerRequest.userInfo objectForKey:@"failedActivityMessage"]];
|
|
786 | 811 |
@synchronized(self) { |
787 | 812 |
// Since the server listing failed in all retries, the operation finished and the sync cycle is completeted unsuccesfully |
788 | 813 |
syncOperationCount = 0; |
... | ... | |
796 | 821 |
- (void)listRequestFailed:(ASIPithosContainerRequest *)containerRequest { |
797 | 822 |
if ([containerRequest isCancelled]) { |
798 | 823 |
[activityFacility endActivity:[containerRequest.userInfo objectForKey:@"activity"] |
799 |
withMessage:@"Sync: Getting server listing (stopped)"];
|
|
824 |
withMessage:[containerRequest.userInfo objectForKey:@"stoppedActivityMessage"]];
|
|
800 | 825 |
[objects release]; |
801 | 826 |
objects = nil; |
802 | 827 |
@synchronized(self) { |
... | ... | |
809 | 834 |
if (retries > 0) { |
810 | 835 |
ASIPithosContainerRequest *newContainerRequest = (ASIPithosContainerRequest *)[PithosUtilities copyRequest:containerRequest]; |
811 | 836 |
[(NSMutableDictionary *)(newContainerRequest.userInfo)setObject:[NSNumber numberWithUnsignedInteger:(--retries)] forKey:@"retries"]; |
812 |
// [[PithosUtilities prepareRequest:newContainerRequest priority:NSOperationQueuePriorityVeryHigh] startAsynchronous]; |
|
813 |
[queue addOperation:[PithosUtilities prepareRequest:newContainerRequest priority:NSOperationQueuePriorityVeryHigh]]; |
|
837 |
[queue addOperation:[PithosUtilities prepareRequest:newContainerRequest priority:[[newContainerRequest.userInfo objectForKey:@"priority"] integerValue]]]; |
|
814 | 838 |
} else { |
815 | 839 |
[activityFacility endActivity:[containerRequest.userInfo objectForKey:@"activity"] |
816 |
withMessage:@"Sync: Getting server listing (failed)"];
|
|
840 |
withMessage:[containerRequest.userInfo objectForKey:@"failedActivityMessage"]];
|
|
817 | 841 |
[objects release]; |
818 | 842 |
objects = nil; |
819 | 843 |
@synchronized(self) { |
... | ... | |
838 | 862 |
[activityFacility endActivity:activity |
839 | 863 |
withMessage:[objectRequest.userInfo objectForKey:@"failedActivityMessage"]]; |
840 | 864 |
@synchronized(self) { |
841 |
syncOperationCount--; |
|
865 |
syncIncomplete = YES; |
|
866 |
[self decreaseSyncOperationCount]; |
|
842 | 867 |
if (newSyncRequested && !syncOperationCount) |
843 | 868 |
[self sync]; |
844 | 869 |
} |
... | ... | |
861 | 886 |
[activityFacility endActivity:activity |
862 | 887 |
withMessage:[objectRequest.userInfo objectForKey:@"failedActivityMessage"]]; |
863 | 888 |
@synchronized(self) { |
864 |
syncOperationCount--; |
|
889 |
syncIncomplete = YES; |
|
890 |
[self decreaseSyncOperationCount]; |
|
865 | 891 |
if (newSyncRequested && !syncOperationCount) |
866 | 892 |
[self sync]; |
867 | 893 |
} |
... | ... | |
895 | 921 |
[activityFacility endActivity:activity |
896 | 922 |
withMessage:[objectRequest.userInfo objectForKey:@"failedActivityMessage"]]; |
897 | 923 |
@synchronized(self) { |
898 |
syncOperationCount--; |
|
924 |
syncIncomplete = YES; |
|
925 |
[self decreaseSyncOperationCount]; |
|
899 | 926 |
if (newSyncRequested && !syncOperationCount) |
900 | 927 |
[self sync]; |
901 | 928 |
} |
... | ... | |
914 | 941 |
[activityFacility endActivity:[objectRequest.userInfo objectForKey:@"activity"] |
915 | 942 |
withMessage:[objectRequest.userInfo objectForKey:@"failedActivityMessage"]]; |
916 | 943 |
@synchronized(self) { |
917 |
syncOperationCount--; |
|
944 |
syncIncomplete = YES; |
|
945 |
[self decreaseSyncOperationCount]; |
|
918 | 946 |
if (newSyncRequested && !syncOperationCount) |
919 | 947 |
[self sync]; |
920 | 948 |
} |
... | ... | |
931 | 959 |
[activityFacility endActivity:activity |
932 | 960 |
withMessage:[objectRequest.userInfo objectForKey:@"failedActivityMessage"]]; |
933 | 961 |
@synchronized(self) { |
934 |
syncOperationCount--; |
|
962 |
syncIncomplete = YES; |
|
963 |
[self decreaseSyncOperationCount]; |
|
935 | 964 |
if (newSyncRequested && !syncOperationCount) |
936 | 965 |
[self sync]; |
937 | 966 |
} |
... | ... | |
957 | 986 |
[self saveLocalState]; |
958 | 987 |
|
959 | 988 |
@synchronized(self) { |
960 |
syncOperationCount--;
|
|
989 |
[self decreaseSyncOperationCount];
|
|
961 | 990 |
if (newSyncRequested && !syncOperationCount) |
962 | 991 |
[self sync]; |
963 | 992 |
} |
... | ... | |
967 | 996 |
[activityFacility endActivity:[objectRequest.userInfo objectForKey:@"activity"] |
968 | 997 |
withMessage:[objectRequest.userInfo objectForKey:@"stoppedActivityMessage"]]; |
969 | 998 |
@synchronized(self) { |
970 |
syncOperationCount--; |
|
999 |
syncIncomplete = YES; |
|
1000 |
[self decreaseSyncOperationCount]; |
|
971 | 1001 |
if (!syncOperationCount) |
972 | 1002 |
[self sync]; |
973 | 1003 |
} |
... | ... | |
991 | 1021 |
totalBytes:activity.totalBytes |
992 | 1022 |
currentBytes:(activity.currentBytes + size)]; |
993 | 1023 |
}]; |
994 |
// [[PithosUtilities prepareRequest:newObjectRequest priority:NSOperationQueuePriorityHigh] startAsynchronous]; |
|
995 |
[queue addOperation:[PithosUtilities prepareRequest:newObjectRequest priority:NSOperationQueuePriorityHigh]]; |
|
1024 |
[queue addOperation:[PithosUtilities prepareRequest:newObjectRequest priority:[[newObjectRequest.userInfo objectForKey:@"priority"] integerValue]]]; |
|
996 | 1025 |
} |
997 | 1026 |
} |
998 | 1027 |
} else if (objectRequest.responseStatusCode == 412) { |
... | ... | |
1000 | 1029 |
[activityFacility endActivity:[objectRequest.userInfo objectForKey:@"activity"] |
1001 | 1030 |
withMessage:[objectRequest.userInfo objectForKey:@"stoppedActivityMessage"]]; |
1002 | 1031 |
@synchronized(self) { |
1003 |
syncOperationCount--; |
|
1032 |
syncIncomplete = YES; |
|
1033 |
[self decreaseSyncOperationCount]; |
|
1004 | 1034 |
if (newSyncRequested && !syncOperationCount) |
1005 | 1035 |
[self sync]; |
1006 | 1036 |
} |
... | ... | |
1016 | 1046 |
[activityFacility endActivity:[objectRequest.userInfo objectForKey:@"activity"] |
1017 | 1047 |
withMessage:[objectRequest.userInfo objectForKey:@"stoppedActivityMessage"]]; |
1018 | 1048 |
@synchronized(self) { |
1019 |
syncOperationCount--; |
|
1049 |
syncIncomplete = YES; |
|
1050 |
[self decreaseSyncOperationCount]; |
|
1020 | 1051 |
if (!syncOperationCount) |
1021 | 1052 |
[self sync]; |
1022 | 1053 |
} |
... | ... | |
1058 | 1089 |
totalBytes:activity.totalBytes |
1059 | 1090 |
currentBytes:(activity.currentBytes + size)]; |
1060 | 1091 |
}]; |
1061 |
// [[PithosUtilities prepareRequest:newObjectRequest priority:NSOperationQueuePriorityHigh] startAsynchronous]; |
|
1062 |
[queue addOperation:[PithosUtilities prepareRequest:newObjectRequest priority:NSOperationQueuePriorityHigh]]; |
|
1092 |
[queue addOperation:[PithosUtilities prepareRequest:newObjectRequest priority:[[newObjectRequest.userInfo objectForKey:@"priority"] integerValue]]]; |
|
1063 | 1093 |
} |
1064 | 1094 |
} else { |
1065 | 1095 |
[self requestFailed:objectRequest]; |
... | ... | |
1075 | 1105 |
[activityFacility endActivity:[objectRequest.userInfo objectForKey:@"activity"] |
1076 | 1106 |
withMessage:[objectRequest.userInfo objectForKey:@"finishedActivityMessage"]]; |
1077 | 1107 |
@synchronized(self) { |
1078 |
syncOperationCount--;
|
|
1108 |
[self decreaseSyncOperationCount];
|
|
1079 | 1109 |
if (newSyncRequested && !syncOperationCount) |
1080 | 1110 |
[self sync]; |
1081 | 1111 |
} |
... | ... | |
1084 | 1114 |
} |
1085 | 1115 |
} |
1086 | 1116 |
|
1087 |
- (void)deleteObjectFinished:(ASIPithosObjectRequest *)objectRequest {
|
|
1088 |
NSLog(@"Sync::delete object finished: %@", objectRequest.url);
|
|
1089 |
if (objectRequest.responseStatusCode == 204) {
|
|
1117 |
- (void)moveObjectToTrashFinished:(ASIPithosObjectRequest *)objectRequest {
|
|
1118 |
NSLog(@"Sync::move object to trash finished: %@", objectRequest.url);
|
|
1119 |
if (objectRequest.responseStatusCode == 201) {
|
|
1090 | 1120 |
[storedLocalObjectStates removeObjectForKey:[[objectRequest.userInfo objectForKey:@"pithosObject"] name]]; |
1091 | 1121 |
[self saveLocalState]; |
1092 | 1122 |
[activityFacility endActivity:[objectRequest.userInfo objectForKey:@"activity"] |
1093 | 1123 |
withMessage:[objectRequest.userInfo objectForKey:@"finishedActivityMessage"]]; |
1094 | 1124 |
@synchronized(self) { |
1095 |
syncOperationCount--;
|
|
1125 |
[self decreaseSyncOperationCount];
|
|
1096 | 1126 |
if (newSyncRequested && !syncOperationCount) |
1097 | 1127 |
[self sync]; |
1098 | 1128 |
} |
... | ... | |
1121 | 1151 |
totalBytes:totalBytes |
1122 | 1152 |
currentBytes:totalBytes]; |
1123 | 1153 |
@synchronized(self) { |
1124 |
syncOperationCount--;
|
|
1154 |
[self decreaseSyncOperationCount];
|
|
1125 | 1155 |
if (newSyncRequested && !syncOperationCount) |
1126 | 1156 |
[self sync]; |
1127 | 1157 |
} |
... | ... | |
1130 | 1160 |
[activityFacility endActivity:activity |
1131 | 1161 |
withMessage:[objectRequest.userInfo objectForKey:@"stoppedActivityMessage"]]; |
1132 | 1162 |
@synchronized(self) { |
1133 |
syncOperationCount--; |
|
1163 |
syncIncomplete = YES; |
|
1164 |
[self decreaseSyncOperationCount]; |
|
1134 | 1165 |
if (!syncOperationCount) |
1135 | 1166 |
[self sync]; |
1136 | 1167 |
} |
... | ... | |
1140 | 1171 |
if (iteration == 0) { |
1141 | 1172 |
NSLog(@"Sync::upload iteration limit reached: %@", objectRequest.url); |
1142 | 1173 |
[activityFacility endActivity:activity |
1143 |
withMessage:[objectRequest.userInfo objectForKey:@"stoppedActivityMessage"]]; |
|
1144 |
@synchronized(self) { |
|
1145 |
syncOperationCount--; |
|
1146 |
} |
|
1174 |
withMessage:[objectRequest.userInfo objectForKey:@"stoppedActivityMessage"]]; |
|
1175 |
syncIncomplete = YES; |
|
1176 |
[self decreaseSyncOperationCount]; |
|
1147 | 1177 |
return; |
1148 | 1178 |
} |
1149 | 1179 |
NSLog(@"Sync::object is missing hashes: %@", objectRequest.url); |
... | ... | |
1175 | 1205 |
totalBytes:activity.totalBytes |
1176 | 1206 |
currentBytes:(activity.currentBytes + size)]; |
1177 | 1207 |
}]; |
1178 |
// [[PithosUtilities prepareRequest:newContainerRequest priority:[[newContainerRequest.userInfo objectForKey:@"priority"] integerValue]] startAsynchronous]; |
|
1179 | 1208 |
[queue addOperation:[PithosUtilities prepareRequest:newContainerRequest priority:[[newContainerRequest.userInfo objectForKey:@"priority"] integerValue]]]; |
1180 | 1209 |
} |
1181 | 1210 |
} else { |
... | ... | |
1217 | 1246 |
[(NSMutableDictionary *)(newObjectRequest.userInfo) setObject:[NSNumber numberWithUnsignedInteger:10] forKey:@"retries"]; |
1218 | 1247 |
[(NSMutableDictionary *)(newObjectRequest.userInfo) removeObjectForKey:@"missingBlocks"]; |
1219 | 1248 |
[(NSMutableDictionary *)(newObjectRequest.userInfo) removeObjectForKey:@"missingBlockIndex"]; |
1220 |
// [[PithosUtilities prepareRequest:newObjectRequest priority:[[newObjectRequest.userInfo objectForKey:@"priority"] integerValue]] startAsynchronous]; |
|
1221 | 1249 |
[queue addOperation:[PithosUtilities prepareRequest:newObjectRequest priority:[[newObjectRequest.userInfo objectForKey:@"priority"] integerValue]]]; |
1222 | 1250 |
} else { |
1223 | 1251 |
if (newSyncRequested) { |
1224 | 1252 |
[activityFacility endActivity:activity |
1225 | 1253 |
withMessage:[containerRequest.userInfo objectForKey:@"stoppedActivityMessage"]]; |
1226 | 1254 |
@synchronized(self) { |
1227 |
syncOperationCount--; |
|
1255 |
syncIncomplete = YES; |
|
1256 |
[self decreaseSyncOperationCount]; |
|
1228 | 1257 |
if (!syncOperationCount) |
1229 | 1258 |
[self sync]; |
1230 | 1259 |
} |
... | ... | |
1247 | 1276 |
totalBytes:activity.totalBytes |
1248 | 1277 |
currentBytes:(activity.currentBytes + size)]; |
1249 | 1278 |
}]; |
1250 |
// [[PithosUtilities prepareRequest:newContainerRequest priority:[[newContainerRequest.userInfo objectForKey:@"priority"] integerValue]] startAsynchronous]; |
|
1251 | 1279 |
[queue addOperation:[PithosUtilities prepareRequest:newContainerRequest priority:[[newContainerRequest.userInfo objectForKey:@"priority"] integerValue]]]; |
1252 | 1280 |
} |
1253 | 1281 |
} |
... | ... | |
1260 | 1288 |
if ([request isCancelled]) { |
1261 | 1289 |
[activityFacility endActivity:[request.userInfo objectForKey:@"activity"] |
1262 | 1290 |
withMessage:[request.userInfo objectForKey:@"stoppedActivityMessage"]]; |
1263 |
@synchronized(self) { |
|
1264 |
syncOperationCount--; |
|
1265 |
} |
|
1291 |
syncIncomplete = YES; |
|
1292 |
[self decreaseSyncOperationCount]; |
|
1266 | 1293 |
return; |
1267 | 1294 |
} |
1268 | 1295 |
if (newSyncRequested) { |
1269 | 1296 |
[activityFacility endActivity:[request.userInfo objectForKey:@"activity"] |
1270 | 1297 |
withMessage:[request.userInfo objectForKey:@"stoppedActivityMessage"]]; |
1271 | 1298 |
@synchronized(self) { |
1272 |
syncOperationCount--; |
|
1299 |
syncIncomplete = YES; |
|
1300 |
[self decreaseSyncOperationCount]; |
|
1273 | 1301 |
if (!syncOperationCount) |
1274 | 1302 |
[self sync]; |
1275 | 1303 |
} |
... | ... | |
1279 | 1307 |
if (retries > 0) { |
1280 | 1308 |
ASIPithosRequest *newRequest = (ASIPithosRequest *)[PithosUtilities copyRequest:request]; |
1281 | 1309 |
[(NSMutableDictionary *)(newRequest.userInfo)setObject:[NSNumber numberWithUnsignedInteger:(--retries)] forKey:@"retries"]; |
1282 |
// [[PithosUtilities prepareRequest:newRequest priority:[[newRequest.userInfo objectForKey:@"priority"] integerValue]] startAsynchronous]; |
|
1283 | 1310 |
[queue addOperation:[PithosUtilities prepareRequest:newRequest priority:[[newRequest.userInfo objectForKey:@"priority"] integerValue]]]; |
1284 | 1311 |
} else { |
1285 | 1312 |
[activityFacility endActivity:[request.userInfo objectForKey:@"activity"] |
1286 | 1313 |
withMessage:[request.userInfo objectForKey:@"failedActivityMessage"]]; |
1287 |
@synchronized(self) { |
|
1288 |
syncOperationCount--; |
|
1289 |
} |
|
1314 |
syncIncomplete = YES; |
|
1315 |
[self decreaseSyncOperationCount]; |
|
1290 | 1316 |
} |
1291 | 1317 |
} |
1292 | 1318 |
|
Also available in: Unified diff