Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

All the pieces are on the floor!

  • Loading branch information...
commit 118b2cbaddcb15504a5277b537bddb0eed94951d 1 parent 03d8955
@ccgus authored
View
2  jstests/sdsetup.jstalk
@@ -136,6 +136,6 @@ function SDSystem(cmd) {
function SDFinish(manager) {
[manager autorelease];
- print("Done with " + SDScriptName);
+ print("*** Done with " + SDScriptName);
}
View
10 jstests/testConflictDiscardServer.jstalk
@@ -13,7 +13,7 @@ runInSD(function() {
var textURL = [SDRemoteURL URLByAppendingPathComponent:@"cj.txt"];
SDPutTextToURL(startText, textURL);
- [m syncWithFinishBlock:[NSApplication new1ArgBlockForJSFunction:function(err) {
+ [m fullSyncWithFinishBlock:[NSApplication new1ArgBlockForJSFunction:function(err) {
// see if we got it.
var s = SDGetLocalFileText("cj.txt")
@@ -26,8 +26,8 @@ runInSD(function() {
// change the text locally.
var localText = @"locally updated text";
SDWriteTextToLocalFile(localText, "cj.txt")
-
- [m syncWithFinishBlock:[NSApplication new1ArgBlockForJSFunction:function(err) {
+ /*
+ [m fullSyncWithFinishBlock:[NSApplication new1ArgBlockForJSFunction:function(err) {
var sText = SDGetTextFromURL(textURL);
SDAssert([sText isEqualTo:localText], "Text was not updated! got:\n'" + sText + "'")
@@ -35,9 +35,9 @@ runInSD(function() {
var lText = SDGetLocalFileText("cj.txt")
SDAssert([lText isEqualTo:localText], "Local was not updated- got '" + s + "'")
- print("Done with " + SDScriptName);
+ SDFinish(m);
}]];
-
+ */
}]];
});
View
6 jstests/testConflictRenameLocal.jstalk
@@ -13,7 +13,7 @@ runInSD(function() {
var textURL = [SDRemoteURL URLByAppendingPathComponent:@"cj.txt"];
SDPutTextToURL(startText, textURL);
- [m syncWithFinishBlock:[NSApplication new1ArgBlockForJSFunction:function(err) {
+ [m fullSyncWithFinishBlock:[NSApplication new1ArgBlockForJSFunction:function(err) {
// see if we got it.
var s = SDGetLocalFileText("cj.txt")
@@ -27,7 +27,7 @@ runInSD(function() {
var localText = @"locally updated text";
SDWriteTextToLocalFile(localText, "cj.txt")
- [m syncWithFinishBlock:[NSApplication new1ArgBlockForJSFunction:function(err) {
+ [m fullSyncWithFinishBlock:[NSApplication new1ArgBlockForJSFunction:function(err) {
var d = [NSCalendarDate calendarDate]
@@ -42,7 +42,7 @@ runInSD(function() {
var lText = SDGetLocalFileText("cj.txt")
SDAssert([lText isEqualTo:serverText], "Local was not updated- got '" + lText + "'")
- print("Done with " + SDScriptName);
+ SDFinish(m);
}]];
}]];
View
8 jstests/testPullDirWithSpace.jstalk
@@ -13,7 +13,7 @@ runInSD(function() {
var textURL = [spaceURL URLByAppendingPathComponent:@"hello world.txt"];
SDPutTextToURL(startText, textURL);
- [m syncWithFinishBlock:[NSApplication new1ArgBlockForJSFunction:function(err) {
+ [m fullSyncWithFinishBlock:[NSApplication new1ArgBlockForJSFunction:function(err) {
// see if we got it.
var s = SDGetLocalFileText("dir with space/hello world.txt")
@@ -23,7 +23,7 @@ runInSD(function() {
var newText = @"Hello World - with more text!";
SDWriteTextToLocalFile(newText, "dir with space/hello world.txt")
- [m syncWithFinishBlock:[NSApplication new1ArgBlockForJSFunction:function(err) {
+ [m fullSyncWithFinishBlock:[NSApplication new1ArgBlockForJSFunction:function(err) {
// get it off the server, make sure it's awesome.
var sText = SDGetTextFromURL(textURL);
@@ -32,10 +32,10 @@ runInSD(function() {
// delete it locally.
SDSystem("rm -rf '" + [SDLocalURL path] + "/dir with space/hello world.txt'")
- [m syncWithFinishBlock:[NSApplication new1ArgBlockForJSFunction:function(err) {
+ [m fullSyncWithFinishBlock:[NSApplication new1ArgBlockForJSFunction:function(err) {
// make sure it isn't on the server anymore.
SDAssert(!SDResourceExistsAtURL(textURL), "The text should be deleted from the server! '" + sText + "'")
- print("Done with " + SDScriptName)
+ SDFinish(m);
}]];
}]];
}]];
View
152 src/SDManager.m
@@ -16,8 +16,8 @@
@interface SDManager ()
- (BOOL)shouldUploadItemAtURL:(NSURL*)aLocalURL;
-- (void)cleanupServerDeletesIfDoneDownloading;
- (void)putChangedFilesFromLocalURL:(NSURL*)lURL;
+- (NSURL*)localPathURLFromServerURI:(NSString*)uri;
@property (retain) NSArray *activeSyncingLocalURLs;
@@ -372,6 +372,13 @@ - (void)request:(FMWebDAVRequest*)request didReceiveAuthenticationChallenge:(NSU
}
}
+- (NSURL*)localPathURLFromServerURL:(NSURL*)surl {
+
+ NSURL *r = [self localPathURLFromServerURI:[surl path]];
+
+ return r;
+}
+
- (NSURL*)localPathURLFromServerURI:(NSString*)uri {
NSString *baseURI = [_remoteURL path];
@@ -480,6 +487,34 @@ - (void)getServerURLIfNeeded:(NSURL*)itemServerURL withPathInfo:(NSDictionary*)p
if (shouldDownload) {
+ NSDate *creDate = [pathInfo objectForKey:FMWebDAVCreationDateKey];
+ NSDate *modDate = [pathInfo objectForKey:FMWebDAVModificationDateKey];
+
+ modDate = (!modDate) ? [NSDate date] : modDate;
+
+ if (!creDate && isServerDir) {
+ // We're on MobileMe, aren't we?
+ creDate = modDate;
+ }
+
+ SDAssert(creDate);
+
+ if (!alreadyExists) {
+ [[self catalog] executeUpdate:@"insert into sync_catalog (path, file_type, etag, created_time, modified_time, sync_check_uuid) values (?, ?, ?, ?, ?, ?)", relPath, isServerDir ? @"fold" : @"file", etag, creDate, modDate, _currentSyncUUID];
+
+ SDAssert(![[self catalog] hadError]);
+
+ }
+ else {
+ [[self catalog] executeUpdate:@"update sync_catalog set sync_check_uuid = ? where path = ?", _currentSyncUUID, relPath];
+ }
+
+
+
+
+
+
+
if (isServerDir) {
NSError *err;
@@ -539,8 +574,12 @@ - (void)getServerURLIfNeeded:(NSURL*)itemServerURL withPathInfo:(NSDictionary*)p
}
debug(@"adding url to request queue");
- [self addURLToRequestQueue:itemServerURL requestAction:@selector(get) withFinishBlock:^(FMWebDAVRequest *getRequest) {
+ //[self addURLToRequestQueue:itemServerURL requestAction:@selector(get) withFinishBlock:^(FMWebDAVRequest *getRequest) {
+ {
+ FMWebDAVRequest *getRequest = [[[FMWebDAVRequest requestToURL:itemServerURL delegate:self] synchronous] get];
+ SDAssert(![getRequest error]);
+ SDAssert([getRequest allHeaderFields]);
debug(@"got the data!");
NSData *writeData = [getRequest responseData];
@@ -587,41 +626,22 @@ - (void)getServerURLIfNeeded:(NSURL*)itemServerURL withPathInfo:(NSDictionary*)p
SDAssert([s isEqualToString:md5]);
}
-
+ }
+ /*
[self removeURLFromActiveQueue:itemServerURL];
- [self cleanupServerDeletesIfDoneDownloading];
- }];
+ }];*/
+
}
}
}
- NSDate *creDate = [pathInfo objectForKey:FMWebDAVCreationDateKey];
- NSDate *modDate = [pathInfo objectForKey:FMWebDAVModificationDateKey];
-
- modDate = (!modDate) ? [NSDate date] : modDate;
-
- if (!creDate && isServerDir) {
- // We're on MobileMe, aren't we?
- creDate = modDate;
- }
-
- SDAssert(creDate);
-
- if (!alreadyExists) {
- [[self catalog] executeUpdate:@"insert into sync_catalog (path, file_type, etag, created_time, modified_time, sync_check_uuid) values (?, ?, ?, ?, ?, ?)", relPath, isServerDir ? @"fold" : @"file", etag, creDate, modDate, _currentSyncUUID];
-
- SDAssert(![[self catalog] hadError]);
-
- }
- else {
- [[self catalog] executeUpdate:@"update sync_catalog set sync_check_uuid = ? where path = ?", _currentSyncUUID, relPath];
- }
}
- (void)finishSyncing {
debug(@"All done!");
FMRelease(_currentSyncUUID);
+ FMRelease(_activeSyncingLocalURLs);
if (_finishBlock) {
_finishBlock(nil);
@@ -636,8 +656,6 @@ - (void)finishSyncing {
- (void)putChangedFilesFromLocalURLs:(NSArray*)lURLs {
- debug(@"lURLs: '%@'", lURLs);
-
for (NSURL *url in lURLs) {
[self putChangedFilesFromLocalURL:url];
}
@@ -656,9 +674,6 @@ - (void)putChangedFilesFromLocalURL:(NSURL*)lURL {
NSFileManager *fm = [[[NSFileManager alloc] init] autorelease];
NSArray *ar = [fm contentsOfDirectoryAtPath:[lURL path] error:&err];
- debug(@"ar: '%@'", ar);
-
-
if (!ar) {
NSLog(@"Error getting subpaths!");
NSLog(@"%@", err);
@@ -673,15 +688,10 @@ - (void)putChangedFilesFromLocalURL:(NSURL*)lURL {
NSString *fullPath = [[lURL path] stringByAppendingPathComponent:path];
NSURL *fullURL = [NSURL fileURLWithPath:fullPath];
- debug(@"Checking: '%@'", fullURL);
-
if (![self shouldUploadItemAtURL:fullURL]) {
- debug(@"nope");
continue;
}
- debug(@"yep");
-
FMResultSet *rs = [[self catalog] executeQuery:@"select etag, md5_when_put from sync_catalog where path = ?", [NSString stringWithFormat:@"/%@", path]];
while ([rs next]) {
found = YES;
@@ -743,6 +753,8 @@ - (void)putChangedFilesFromLocalURL:(NSURL*)lURL {
}
}
+ debug(@"pushUpInfo: '%@'", pushUpInfo);
+
for (NSDictionary *dict in pushUpInfo) {
NSURL *localPushURL = [dict objectForKey:@"url"];
@@ -825,18 +837,6 @@ - (void)putChangedFilesFromLocalURL:(NSURL*)lURL {
BOOL worked = [[self catalog] executeUpdate:@"replace into sync_catalog (path, etag, md5_when_put, sync_check_uuid, server_modified_date_string, weak_etag) values (?, ?, ?, ?, ?, ?)", relativePath, headEtag, localMD5, headDate, [NSNumber numberWithBool:headWeakEtag], _currentSyncUUID];
SDAssert(worked);
- /*
- if (exists) {
- BOOL res = [[self catalog] executeUpdate:@"update sync_catalog set etag = ?, md5_when_put = ?, sync_check_uuid = ?, server_modified_date_string = ?, weak_etag = ? where path = ?", headEtag, localMD5, _currentSyncUUID, headDate, [NSNumber numberWithBool:headWeakEtag], relativePath];
-
- SDAssert(res);
- SDAssert(![[self catalog] hadError]);
- }
- else {
- BOOL res = [[self catalog] executeUpdate:@"insert into sync_catalog (path, etag, md5_when_put, sync_check_uuid, server_modified_date_string, weak_etag) values (?, ?, ?, ?, ?, ?)", relativePath, headEtag, localMD5, headDate, [NSNumber numberWithBool:headWeakEtag], _currentSyncUUID];
- SDAssert(res);
- }
- */
}
else {
NSLog(@"Bad head on %@", pushToURL);
@@ -864,9 +864,7 @@ - (void)putChangedFilesFromLocalURL:(NSURL*)lURL {
- (void)cleanupServerDeletes {
- //debug(@"Entering cleanupServerDeletes");
-
- #pragma message "FIXME: this is totally fucked now. Time to rethink everything. UGH"
+ debug(@"Entering cleanupServerDeletes");
NSMutableArray *localDeletes = [NSMutableArray array];
@@ -878,8 +876,6 @@ - (void)cleanupServerDeletes {
relPath = @"/";
}
-
-
FMResultSet *rs = [[self catalog] executeQuery:@"select path from sync_catalog where sync_check_uuid <> ? and path like ?", _currentSyncUUID, [relPath stringByAppendingString:@"%"]];
while ([rs next]) {
@@ -901,7 +897,7 @@ - (void)cleanupServerDeletes {
for (NSString *relPath in localDeletes) {
- //debug(@"deleting: %@", relPath);
+ debug(@"deleting: %@", relPath);
NSURL *deleteURL = [NSURL fileURLWithPath:[[_localURL path] stringByAppendingString:relPath]];
@@ -915,24 +911,24 @@ - (void)cleanupServerDeletes {
}
[self putChangedFilesFromLocalURLs:_activeSyncingLocalURLs];
-}
-
-
-- (void)cleanupServerDeletesIfDoneDownloading {
- if ([self queueIsEmpty]) {
- [self cleanupServerDeletes];
- }
+ debug(@"Exiting cleanupServerDeletes");
}
+
- (void)getServerChangesAtURLs:(NSArray*)endpointURLs {
+ debug(@"Entering getServerChangesAtURLs");
+
+ SDAssert([NSThread isMainThread]);
SDAssert([endpointURLs count]);
for (NSURL *endpointURL in endpointURLs) {
[self addURLToRequestQueue:endpointURL requestAction:@selector(fetchDirectoryListing) withFinishBlock:^(FMWebDAVRequest *dirRequest) {
+ NSFileManager *fm = [[NSFileManager new] autorelease];
+
if ([dirRequest error]) {
NSLog(@"error fetching directory listing: %@", [dirRequest error]);
}
@@ -945,21 +941,32 @@ - (void)getServerChangesAtURLs:(NSArray*)endpointURLs {
if (([[pathInfo objectForKey:FMWebDAVContentTypeKey] hasSuffix:@"directory"] || [[pathInfo objectForKey:FMWebDAVURIKey] hasSuffix:@"/"])) {
- // hey gus- check and see if the dir exists locally or not. And if it doesn't, then add it to the list.
- abort();
+ NSURL *lURL = [self localPathURLFromServerURL:newURL];
- [self getServerChangesAtURLs:[NSArray arrayWithObject:newURL]];
+ // it's new!
+ if (![fm fileExistsAtPath:[lURL path]]) {
+ debug(@"NEW DIR TO PULL! %@", [lURL path]);
+ abort();
+ //[self getServerChangesAtURLs:[NSArray arrayWithObject:newURL]];
+ }
}
}
[self removeURLFromActiveQueue:endpointURL];
- [self cleanupServerDeletesIfDoneDownloading];
+
+ if ([self queueIsEmpty]) {
+ debug(@"Queue is empty!");
+ [self cleanupServerDeletes];
+ }
}];
}
+
+
+ debug(@"Exiting getServerChangesAtURLs, waiting queue: %ld active queue: %ld", [_waitingQueue count], [_activeQueue count]);
}
-- (void)cleanupLocalDeletesAtURLs:(NSArray*)lURLs {
+- (void)removeLocalDeletesFromServer {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
@@ -968,7 +975,7 @@ - (void)cleanupLocalDeletesAtURLs:(NSArray*)lURLs {
NSFileManager *fm = [[[NSFileManager alloc] init] autorelease];
- for (NSURL *lUrl in lURLs) {
+ for (NSURL *lUrl in _activeSyncingLocalURLs) {
NSString *relativePath = [self relativePathForLocalURL:lUrl];
@@ -1070,7 +1077,8 @@ - (void)syncLocalURLs:(NSArray*)lURLs withFinishBlock:(void (^)(NSError *))finis
}
if (_currentSyncUUID) {
-
+ abort();
+ /*
for (NSURL *url in lURLs) {
NSUInteger alreadyAround = [_urlsToScanAfterSupressionLifts indexOfObjectPassingTest:^(NSURL *existingURL, NSUInteger idx, BOOL *stop) {
@@ -1090,16 +1098,20 @@ - (void)syncLocalURLs:(NSArray*)lURLs withFinishBlock:(void (^)(NSError *))finis
}
return;
+ */
}
_currentSyncUUID = [[NSString stringWithUUID] retain];
[self setFinishBlock:finishBlock];
+ if (_activeSyncingLocalURLs) {
+ abort();
+ }
+
[self setActiveSyncingLocalURLs:lURLs];
- #pragma message "FIXME: why the fuck am I passing along these urls, when I've also got an ivar for them?"
- [self cleanupLocalDeletesAtURLs:lURLs];
+ [self removeLocalDeletesFromServer];
}
- (void)stop {
View
2  src/fmwebdav/FMWebDAVRequest.m
@@ -202,6 +202,8 @@ - (void)sendRequest:(NSMutableURLRequest *)req {
[self logRequest:req];
[self logResponse:httpResponse];
+ [self setAllHeaderFields:[httpResponse allHeaderFields]];
+
_responseStatusCode = [httpResponse statusCode];
}
Please sign in to comment.
Something went wrong with that request. Please try again.