Revision 919cb043 pithos-macos/PithosSyncDaemon.m
b/pithos-macos/PithosSyncDaemon.m | ||
---|---|---|
2 | 2 |
// PithosSyncDaemon.m |
3 | 3 |
// pithos-macos |
4 | 4 |
// |
5 |
// Copyright 2011 GRNET S.A. All rights reserved. |
|
5 |
// Copyright 2011-2012 GRNET S.A. All rights reserved.
|
|
6 | 6 |
// |
7 | 7 |
// Redistribution and use in source and binary forms, with or |
8 | 8 |
// without modification, are permitted provided that the following |
... | ... | |
41 | 41 |
#import "PithosUtilities.h" |
42 | 42 |
#import "ASINetworkQueue.h" |
43 | 43 |
#import "ASIPithosRequest.h" |
44 |
#import "ASIPithos.h" |
|
44 | 45 |
#import "ASIPithosContainerRequest.h" |
45 | 46 |
#import "ASIPithosObjectRequest.h" |
46 | 47 |
#import "ASIPithosObject.h" |
... | ... | |
72 | 73 |
#pragma Object Lifecycle |
73 | 74 |
|
74 | 75 |
- (id)initWithDirectoryPath:(NSString *)aDirectoryPath |
76 |
pithos:(ASIPithos *)aPithos |
|
75 | 77 |
containerName:(NSString *)aContainerName |
76 | 78 |
timeInterval:(NSTimeInterval)aTimeInterval |
77 | 79 |
resetLocalState:(BOOL)resetLocalState { |
78 | 80 |
if ((self = [super init])) { |
79 | 81 |
directoryPath = [aDirectoryPath copy]; |
82 |
pithos = [aPithos retain]; |
|
80 | 83 |
containerName = [aContainerName copy]; |
81 | 84 |
timeInterval = aTimeInterval; |
82 | 85 |
|
... | ... | |
160 | 163 |
[lastModified release]; |
161 | 164 |
[blockHash release]; |
162 | 165 |
[containerName release]; |
166 |
[pithos release]; |
|
163 | 167 |
[directoryPath release]; |
164 | 168 |
[super dealloc]; |
165 | 169 |
} |
... | ... | |
330 | 334 |
return; |
331 | 335 |
} |
332 | 336 |
|
333 |
ASIPithosContainerRequest *containerRequest = [ASIPithosContainerRequest listObjectsRequestWithContainerName:containerName |
|
334 |
limit:0 |
|
335 |
marker:nil |
|
336 |
prefix:nil |
|
337 |
delimiter:nil |
|
338 |
path:nil |
|
339 |
meta:nil |
|
340 |
shared:NO |
|
341 |
until:nil |
|
342 |
ifModifiedSince:lastModified]; |
|
337 |
ASIPithosContainerRequest *containerRequest = [ASIPithosContainerRequest listObjectsRequestWithPithos:pithos |
|
338 |
containerName:containerName |
|
339 |
limit:0 |
|
340 |
marker:nil |
|
341 |
prefix:nil |
|
342 |
delimiter:nil |
|
343 |
path:nil |
|
344 |
meta:nil |
|
345 |
shared:NO |
|
346 |
until:nil |
|
347 |
ifModifiedSince:lastModified]; |
|
343 | 348 |
containerRequest.delegate = self; |
344 | 349 |
containerRequest.didFinishSelector = @selector(performRequestFinishedDelegateInBackground:); |
345 | 350 |
containerRequest.didFailSelector = @selector(performRequestFailedDelegateInBackground:); |
... | ... | |
571 | 576 |
// Remote updated info |
572 | 577 |
NSError *remoteError; |
573 | 578 |
BOOL remoteIsDirectory; |
574 |
BOOL remoteObjectExists = [PithosUtilities objectExistsAtContainerName:containerName |
|
575 |
objectName:object.name |
|
576 |
error:&remoteError |
|
577 |
isDirectory:&remoteIsDirectory |
|
578 |
sharingAccount:nil]; |
|
579 |
BOOL remoteObjectExists = [PithosUtilities objectExistsAtPithos:pithos |
|
580 |
containerName:containerName |
|
581 |
objectName:object.name |
|
582 |
error:&remoteError |
|
583 |
isDirectory:&remoteIsDirectory |
|
584 |
sharingAccount:nil]; |
|
579 | 585 |
if (!object || !object.objectHash) { |
580 | 586 |
// Delete local object |
581 | 587 |
if (remoteObjectExists) { |
... | ... | |
692 | 698 |
}); |
693 | 699 |
} else { |
694 | 700 |
[self increaseSyncOperationCount]; |
695 |
__block ASIPithosObjectRequest *objectRequest = [PithosUtilities objectBlockDataRequestWithContainerName:containerName |
|
696 |
object:object |
|
697 |
blockIndex:0 |
|
698 |
blockSize:blockSize]; |
|
701 |
__block ASIPithosObjectRequest *objectRequest = [PithosUtilities objectBlockDataRequestWithPithos:pithos |
|
702 |
containerName:containerName |
|
703 |
object:object |
|
704 |
blockIndex:0 |
|
705 |
blockSize:blockSize]; |
|
699 | 706 |
objectRequest.delegate = self; |
700 | 707 |
objectRequest.didFinishSelector = @selector(performRequestFinishedDelegateInBackground:); |
701 | 708 |
objectRequest.didFailSelector = @selector(performRequestFailedDelegateInBackground:); |
... | ... | |
758 | 765 |
storedState.tmpFilePath = nil; |
759 | 766 |
} else { |
760 | 767 |
[self increaseSyncOperationCount]; |
761 |
ASIPithosObjectRequest *objectRequest = [ASIPithosObjectRequest objectHashmapRequestWithContainerName:containerName |
|
762 |
objectName:object.name]; |
|
768 |
ASIPithosObjectRequest *objectRequest = [ASIPithosObjectRequest objectHashmapRequestWithPithos:pithos |
|
769 |
containerName:containerName |
|
770 |
objectName:object.name]; |
|
763 | 771 |
objectRequest.delegate = self; |
764 | 772 |
objectRequest.didFinishSelector = @selector(performRequestFinishedDelegateInBackground:); |
765 | 773 |
objectRequest.didFailSelector = @selector(performRequestFailedDelegateInBackground:); |
... | ... | |
805 | 813 |
[pool drain]; |
806 | 814 |
return; |
807 | 815 |
} |
808 |
ASIPithosObjectRequest *objectRequest = [ASIPithosObjectRequest writeObjectDataRequestWithContainerName:containerName |
|
809 |
objectName:object.name |
|
810 |
eTag:nil |
|
811 |
contentType:@"application/directory" |
|
812 |
contentEncoding:nil |
|
813 |
contentDisposition:nil |
|
814 |
manifest:nil |
|
815 |
sharing:nil |
|
816 |
isPublic:ASIPithosObjectRequestPublicIgnore |
|
817 |
metadata:nil |
|
818 |
data:[NSData data]]; |
|
816 |
ASIPithosObjectRequest *objectRequest = [ASIPithosObjectRequest writeObjectDataRequestWithPithos:pithos |
|
817 |
containerName:containerName |
|
818 |
objectName:object.name |
|
819 |
eTag:nil |
|
820 |
contentType:@"application/directory" |
|
821 |
contentEncoding:nil |
|
822 |
contentDisposition:nil |
|
823 |
manifest:nil |
|
824 |
sharing:nil |
|
825 |
isPublic:ASIPithosObjectRequestPublicIgnore |
|
826 |
metadata:nil |
|
827 |
data:[NSData data]]; |
|
819 | 828 |
objectRequest.delegate = self; |
820 | 829 |
objectRequest.didFinishSelector = @selector(performRequestFinishedDelegateInBackground:); |
821 | 830 |
objectRequest.didFailSelector = @selector(performRequestFailedDelegateInBackground:); |
... | ... | |
844 | 853 |
} |
845 | 854 |
NSString *safeName; |
846 | 855 |
if ([PithosUtilities isContentTypeDirectory:object.contentType]) |
847 |
safeName = [PithosUtilities safeSubdirNameForContainerName:@"trash" |
|
848 |
subdirName:object.name]; |
|
856 |
safeName = [PithosUtilities safeSubdirNameForPithos:pithos containerName:@"trash" subdirName:object.name]; |
|
849 | 857 |
else |
850 |
safeName = [PithosUtilities safeObjectNameForContainerName:@"trash" |
|
851 |
objectName:object.name]; |
|
858 |
safeName = [PithosUtilities safeObjectNameForPithos:pithos containerName:@"trash" objectName:object.name]; |
|
852 | 859 |
if (safeName) { |
853 |
ASIPithosObjectRequest *objectRequest = [PithosUtilities moveObjectRequestWithContainerName:containerName |
|
854 |
objectName:object.name |
|
855 |
destinationContainerName:@"trash" |
|
856 |
destinationObjectName:safeName |
|
857 |
checkIfExists:NO]; |
|
860 |
ASIPithosObjectRequest *objectRequest = [PithosUtilities moveObjectRequestWithPithos:pithos |
|
861 |
containerName:containerName |
|
862 |
objectName:object.name |
|
863 |
destinationContainerName:@"trash" |
|
864 |
destinationObjectName:safeName |
|
865 |
checkIfExists:NO]; |
|
858 | 866 |
if (objectRequest) { |
859 | 867 |
objectRequest.delegate = self; |
860 | 868 |
objectRequest.didFinishSelector = @selector(performRequestFinishedDelegateInBackground:); |
... | ... | |
900 | 908 |
if (error) |
901 | 909 |
NSLog(@"contentType detection error: %@", error); |
902 | 910 |
NSArray *hashes = nil; |
903 |
ASIPithosObjectRequest *objectRequest = [PithosUtilities writeObjectDataRequestWithContainerName:containerName |
|
904 |
objectName:object.name |
|
905 |
contentType:object.contentType |
|
906 |
blockSize:blockSize |
|
907 |
blockHash:blockHash |
|
908 |
forFile:filePath |
|
909 |
checkIfExists:NO |
|
910 |
hashes:&hashes |
|
911 |
sharingAccount:nil]; |
|
911 |
ASIPithosObjectRequest *objectRequest = [PithosUtilities writeObjectDataRequestWithPithos:pithos |
|
912 |
containerName:containerName |
|
913 |
objectName:object.name |
|
914 |
contentType:object.contentType |
|
915 |
blockSize:blockSize |
|
916 |
blockHash:blockHash |
|
917 |
forFile:filePath |
|
918 |
checkIfExists:NO |
|
919 |
hashes:&hashes |
|
920 |
sharingAccount:nil]; |
|
912 | 921 |
if (objectRequest) { |
913 | 922 |
objectRequest.delegate = self; |
914 | 923 |
objectRequest.didFinishSelector = @selector(performRequestFinishedDelegateInBackground:); |
... | ... | |
982 | 991 |
objects = nil; |
983 | 992 |
} else { |
984 | 993 |
// Do an additional request to fetch more objects |
985 |
ASIPithosContainerRequest *newContainerRequest = [ASIPithosContainerRequest listObjectsRequestWithContainerName:containerName |
|
986 |
limit:0 |
|
987 |
marker:[[someObjects lastObject] name] |
|
988 |
prefix:nil |
|
989 |
delimiter:nil |
|
990 |
path:nil |
|
991 |
meta:nil |
|
992 |
shared:NO |
|
993 |
until:nil |
|
994 |
ifModifiedSince:lastModified]; |
|
994 |
ASIPithosContainerRequest *newContainerRequest = [ASIPithosContainerRequest listObjectsRequestWithPithos:pithos |
|
995 |
containerName:containerName |
|
996 |
limit:0 |
|
997 |
marker:[[someObjects lastObject] name] |
|
998 |
prefix:nil |
|
999 |
delimiter:nil |
|
1000 |
path:nil |
|
1001 |
meta:nil |
|
1002 |
shared:NO |
|
1003 |
until:nil |
|
1004 |
ifModifiedSince:lastModified]; |
|
995 | 1005 |
newContainerRequest.delegate = self; |
996 | 1006 |
newContainerRequest.didFinishSelector = @selector(performRequestFinishedDelegateInBackground:); |
997 | 1007 |
newContainerRequest.didFailSelector = @selector(performRequestFailedDelegateInBackground:); |
... | ... | |
1375 | 1385 |
[pool drain]; |
1376 | 1386 |
return; |
1377 | 1387 |
} else { |
1378 |
__block ASIPithosObjectRequest *newObjectRequest = [PithosUtilities objectBlockDataRequestWithContainerName:containerName |
|
1379 |
object:object |
|
1380 |
blockIndex:missingBlockIndex |
|
1381 |
blockSize:blockSize]; |
|
1388 |
__block ASIPithosObjectRequest *newObjectRequest = [PithosUtilities objectBlockDataRequestWithPithos:pithos |
|
1389 |
containerName:containerName |
|
1390 |
object:object |
|
1391 |
blockIndex:missingBlockIndex |
|
1392 |
blockSize:blockSize]; |
|
1382 | 1393 |
newObjectRequest.delegate = self; |
1383 | 1394 |
newObjectRequest.didFinishSelector = @selector(performRequestFinishedDelegateInBackground:); |
1384 | 1395 |
newObjectRequest.didFailSelector = @selector(performRequestFailedDelegateInBackground:); |
... | ... | |
1451 | 1462 |
currentBytes:(activity.totalBytes - [missingBlocks count]*blockSize)]; |
1452 | 1463 |
}); |
1453 | 1464 |
|
1454 |
__block ASIPithosObjectRequest *newObjectRequest = [PithosUtilities objectBlockDataRequestWithContainerName:containerName |
|
1455 |
object:object |
|
1456 |
blockIndex:missingBlockIndex |
|
1457 |
blockSize:blockSize]; |
|
1465 |
__block ASIPithosObjectRequest *newObjectRequest = [PithosUtilities objectBlockDataRequestWithPithos:pithos |
|
1466 |
containerName:containerName |
|
1467 |
object:object |
|
1468 |
blockIndex:missingBlockIndex |
|
1469 |
blockSize:blockSize]; |
|
1458 | 1470 |
newObjectRequest.delegate = self; |
1459 | 1471 |
newObjectRequest.didFinishSelector = @selector(performRequestFinishedDelegateInBackground:); |
1460 | 1472 |
newObjectRequest.didFailSelector = @selector(performRequestFailedDelegateInBackground:); |
... | ... | |
1574 | 1586 |
} |
1575 | 1587 |
NSLog(@"Sync::object is missing hashes: %@", objectRequest.url); |
1576 | 1588 |
NSIndexSet *missingBlocks = [PithosUtilities missingBlocksForHashes:[objectRequest.userInfo objectForKey:@"hashes"] |
1577 |
withMissingHashesResponse:[objectRequest responseString]];
|
|
1589 |
withMissingHashes:[objectRequest hashes]];
|
|
1578 | 1590 |
if (totalBytes >= [missingBlocks count]*blockSize) |
1579 | 1591 |
currentBytes = totalBytes - [missingBlocks count]*blockSize; |
1580 | 1592 |
dispatch_async(dispatch_get_main_queue(), ^{ |
... | ... | |
1584 | 1596 |
currentBytes:currentBytes]; |
1585 | 1597 |
}); |
1586 | 1598 |
NSUInteger missingBlockIndex = [missingBlocks firstIndex]; |
1587 |
__block ASIPithosContainerRequest *newContainerRequest = [PithosUtilities updateContainerDataRequestWithContainerName:containerName |
|
1588 |
blockSize:blockSize |
|
1589 |
forFile:[objectRequest.userInfo objectForKey:@"filePath"] |
|
1590 |
missingBlockIndex:missingBlockIndex |
|
1591 |
sharingAccount:nil]; |
|
1599 |
__block ASIPithosContainerRequest *newContainerRequest = [PithosUtilities updateContainerDataRequestWithPithos:pithos |
|
1600 |
containerName:containerName |
|
1601 |
blockSize:blockSize |
|
1602 |
forFile:[objectRequest.userInfo objectForKey:@"filePath"] |
|
1603 |
missingBlockIndex:missingBlockIndex |
|
1604 |
sharingAccount:nil]; |
|
1592 | 1605 |
newContainerRequest.delegate = self; |
1593 | 1606 |
newContainerRequest.didFinishSelector = @selector(performRequestFinishedDelegateInBackground:); |
1594 | 1607 |
newContainerRequest.didFailSelector = @selector(performRequestFailedDelegateInBackground:); |
... | ... | |
1623 | 1636 |
missingBlockIndex = [missingBlocks indexGreaterThanIndex:missingBlockIndex]; |
1624 | 1637 |
if (missingBlockIndex == NSNotFound) { |
1625 | 1638 |
NSArray *hashes = [containerRequest.userInfo objectForKey:@"hashes"]; |
1626 |
ASIPithosObjectRequest *newObjectRequest = [PithosUtilities writeObjectDataRequestWithContainerName:containerName |
|
1627 |
objectName:object.name |
|
1628 |
contentType:object.contentType |
|
1629 |
blockSize:blockSize |
|
1630 |
blockHash:blockHash |
|
1631 |
forFile:[containerRequest.userInfo objectForKey:@"filePath"] |
|
1632 |
checkIfExists:NO |
|
1633 |
hashes:&hashes |
|
1634 |
sharingAccount:nil]; |
|
1639 |
ASIPithosObjectRequest *newObjectRequest = [PithosUtilities writeObjectDataRequestWithPithos:pithos |
|
1640 |
containerName:containerName |
|
1641 |
objectName:object.name |
|
1642 |
contentType:object.contentType |
|
1643 |
blockSize:blockSize |
|
1644 |
blockHash:blockHash |
|
1645 |
forFile:[containerRequest.userInfo objectForKey:@"filePath"] |
|
1646 |
checkIfExists:NO |
|
1647 |
hashes:&hashes |
|
1648 |
sharingAccount:nil]; |
|
1635 | 1649 |
newObjectRequest.delegate = self; |
1636 | 1650 |
newObjectRequest.didFinishSelector = @selector(performRequestFinishedDelegateInBackground:); |
1637 | 1651 |
newObjectRequest.didFailSelector = @selector(performRequestFailedDelegateInBackground:); |
... | ... | |
1656 | 1670 |
[pool drain]; |
1657 | 1671 |
return; |
1658 | 1672 |
} else { |
1659 |
__block ASIPithosContainerRequest *newContainerRequest = [PithosUtilities updateContainerDataRequestWithContainerName:containerName |
|
1660 |
blockSize:blockSize |
|
1661 |
forFile:[containerRequest.userInfo objectForKey:@"filePath"] |
|
1662 |
missingBlockIndex:missingBlockIndex |
|
1663 |
sharingAccount:nil]; |
|
1673 |
__block ASIPithosContainerRequest *newContainerRequest = [PithosUtilities updateContainerDataRequestWithPithos:pithos |
|
1674 |
containerName:containerName |
|
1675 |
blockSize:blockSize |
|
1676 |
forFile:[containerRequest.userInfo objectForKey:@"filePath"] |
|
1677 |
missingBlockIndex:missingBlockIndex |
|
1678 |
sharingAccount:nil]; |
|
1664 | 1679 |
newContainerRequest.delegate = self; |
1665 | 1680 |
newContainerRequest.didFinishSelector = @selector(performRequestFinishedDelegateInBackground:); |
1666 | 1681 |
newContainerRequest.didFailSelector = @selector(performRequestFailedDelegateInBackground:); |
Also available in: Unified diff