Revision 4a8699ab
b/pithos-macos/PithosAccountNode.m | ||
---|---|---|
42 | 42 |
#import "ASIPithosContainer.h" |
43 | 43 |
#import "ASIDownloadCache.h" |
44 | 44 |
#import "PithosUtilities.h" |
45 |
#import "PithosActivityFacility.h" |
|
45 | 46 |
|
46 | 47 |
static NSImage *sharedIcon = nil; |
47 | 48 |
|
... | ... | |
95 | 96 |
accountRequest.delegate = self; |
96 | 97 |
accountRequest.didFinishSelector = @selector(accountRequestFinished:); |
97 | 98 |
accountRequest.didFailSelector = @selector(accountRequestFailed:); |
99 |
accountRequest.userInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys: |
|
100 |
[NSNumber numberWithUnsignedInteger:10], @"retries", |
|
101 |
nil]; |
|
98 | 102 |
if (!forcedRefresh) |
99 | 103 |
accountRequest.downloadCache = [ASIDownloadCache sharedCache]; |
100 | 104 |
[[PithosUtilities prepareRequest:accountRequest priority:NSOperationQueuePriorityVeryHigh] startAsynchronous]; |
... | ... | |
130 | 134 |
#pragma mark - |
131 | 135 |
#pragma mark ASIHTTPRequestDelegate |
132 | 136 |
|
133 |
- (void)accountRequestFinished:(ASIPithosAccountRequest *)request { |
|
134 |
NSLog(@"URL: %@", [accountRequest url]); |
|
135 |
NSLog(@"cached: %d", [accountRequest didUseCachedResponse]); |
|
136 |
|
|
137 |
self.pithosAccount = [accountRequest account]; |
|
138 |
|
|
139 |
NSArray *someContainers = [accountRequest containers]; |
|
140 |
if (containers == nil) { |
|
141 |
containers = [[NSMutableArray alloc] initWithArray:someContainers]; |
|
137 |
- (void)accountRequestFailed:(ASIPithosAccountRequest *)request { |
|
138 |
NSUInteger retries = [[accountRequest.userInfo objectForKey:@"retries"] unsignedIntegerValue]; |
|
139 |
if (retries > 0) { |
|
140 |
ASIPithosAccountRequest *newAccountRequest = (ASIPithosAccountRequest *)[PithosUtilities copyRequest:accountRequest]; |
|
141 |
[(NSMutableDictionary *)(newAccountRequest.userInfo)setObject:[NSNumber numberWithUnsignedInteger:(--retries)] forKey:@"retries"]; |
|
142 |
[accountRequest release]; |
|
143 |
accountRequest = newAccountRequest; |
|
144 |
[[PithosUtilities prepareRequest:accountRequest priority:NSOperationQueuePriorityVeryHigh] startAsynchronous]; |
|
142 | 145 |
} else { |
143 |
[containers addObjectsFromArray:someContainers]; |
|
146 |
NSString *message; |
|
147 |
NSError *error = [accountRequest error]; |
|
148 |
if (error) |
|
149 |
message = [NSString stringWithFormat:@"Account listing failed: %@", error]; |
|
150 |
else |
|
151 |
message = [NSString stringWithFormat:@"Account listing failed: (%d) %@", |
|
152 |
accountRequest.responseStatusCode, accountRequest.responseStatusMessage]; |
|
153 |
[[PithosActivityFacility defaultPithosActivityFacility] startAndEndActivityWithType:PithosActivityOther message:message]; |
|
154 |
[newChildren release]; |
|
155 |
newChildren = nil; |
|
156 |
[accountRequest release]; |
|
157 |
accountRequest = nil; |
|
158 |
[containers release]; |
|
159 |
containers = nil; |
|
160 |
forcedRefresh = NO; |
|
161 |
@synchronized(self) { |
|
162 |
freshness = PithosNodeStateRefreshNeeded; |
|
163 |
} |
|
144 | 164 |
} |
145 |
if ([someContainers count] < 10000) { |
|
146 |
if (!accountRequest.didUseCachedResponse || ([containers count] != [someContainers count]) || !children) { |
|
147 |
// Save new children |
|
148 |
NSLog(@"using newChildren"); |
|
149 |
newChildren = [[NSMutableArray alloc] init]; |
|
150 |
NSMutableIndexSet *keptNodes = [NSMutableIndexSet indexSet]; |
|
151 |
for (ASIPithosContainer *container in containers) { |
|
152 |
PithosContainerNode *node = [[[PithosContainerNode alloc] initWithPithosContainer:container] autorelease]; |
|
153 |
node.parent = self; |
|
154 |
node.shared = shared; |
|
155 |
node.sharingAccount = sharingAccount; |
|
156 |
if (children) { |
|
157 |
NSUInteger oldIndex = [children indexOfObject:node]; |
|
158 |
if (oldIndex != NSNotFound) { |
|
159 |
// Use the same pointer value, if possible |
|
160 |
node = [children objectAtIndex:oldIndex]; |
|
161 |
node.pithosContainer = container; |
|
162 |
[keptNodes addIndex:oldIndex]; |
|
165 |
} |
|
166 |
|
|
167 |
- (void)accountRequestFinished:(ASIPithosAccountRequest *)request { |
|
168 |
NSLog(@"List account finished: %@", [accountRequest url]); |
|
169 |
NSLog(@"Cached: %d", [accountRequest didUseCachedResponse]); |
|
170 |
if (accountRequest.responseStatusCode == 200) { |
|
171 |
self.pithosAccount = [accountRequest account]; |
|
172 |
|
|
173 |
NSArray *someContainers = [accountRequest containers]; |
|
174 |
if (containers == nil) { |
|
175 |
containers = [[NSMutableArray alloc] initWithArray:someContainers]; |
|
176 |
} else { |
|
177 |
[containers addObjectsFromArray:someContainers]; |
|
178 |
} |
|
179 |
if ([someContainers count] < 10000) { |
|
180 |
if (!accountRequest.didUseCachedResponse || ([containers count] != [someContainers count]) || !children) { |
|
181 |
// Save new children |
|
182 |
NSLog(@"using newChildren"); |
|
183 |
newChildren = [[NSMutableArray alloc] init]; |
|
184 |
NSMutableIndexSet *keptNodes = [NSMutableIndexSet indexSet]; |
|
185 |
for (ASIPithosContainer *container in containers) { |
|
186 |
PithosContainerNode *node = [[[PithosContainerNode alloc] initWithPithosContainer:container] autorelease]; |
|
187 |
node.parent = self; |
|
188 |
node.shared = shared; |
|
189 |
node.sharingAccount = sharingAccount; |
|
190 |
if (children) { |
|
191 |
NSUInteger oldIndex = [children indexOfObject:node]; |
|
192 |
if (oldIndex != NSNotFound) { |
|
193 |
// Use the same pointer value, if possible |
|
194 |
node = [children objectAtIndex:oldIndex]; |
|
195 |
node.pithosContainer = container; |
|
196 |
[keptNodes addIndex:oldIndex]; |
|
197 |
} |
|
163 | 198 |
} |
199 |
[newChildren addObject:node]; |
|
164 | 200 |
} |
165 |
[newChildren addObject:node]; |
|
201 |
[[children objectsAtIndexes: |
|
202 |
[[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, [children count])] indexesPassingTest:^(NSUInteger idx, BOOL *stop){ |
|
203 |
if ([keptNodes containsIndex:idx]) |
|
204 |
return NO; |
|
205 |
return YES; |
|
206 |
}]] makeObjectsPerformSelector:@selector(pithosNodeWillBeRemoved)]; |
|
207 |
} |
|
208 |
// Else cache was used and all results were fetched during this request, so existing children can be reused |
|
209 |
[accountRequest release]; |
|
210 |
accountRequest = nil; |
|
211 |
[containers release]; |
|
212 |
containers = nil; |
|
213 |
forcedRefresh = NO; |
|
214 |
@synchronized(self) { |
|
215 |
freshness = PithosNodeStateRefreshFinished; |
|
166 | 216 |
} |
167 |
[[children objectsAtIndexes: |
|
168 |
[[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, [children count])] indexesPassingTest:^(NSUInteger idx, BOOL *stop){ |
|
169 |
if ([keptNodes containsIndex:idx]) |
|
170 |
return NO; |
|
171 |
return YES; |
|
172 |
}]] makeObjectsPerformSelector:@selector(pithosNodeWillBeRemoved)]; |
|
217 |
// Notify observers that children are updated |
|
218 |
[[NSNotificationCenter defaultCenter] postNotificationName:@"PithosAccountNodeChildrenUpdated" object:self]; |
|
219 |
} else { |
|
220 |
[accountRequest release]; |
|
221 |
// Do an additional request to fetch more objects |
|
222 |
accountRequest = [[ASIPithosAccountRequest listContainersRequestWithLimit:0 |
|
223 |
marker:[[someContainers lastObject] name] |
|
224 |
shared:shared |
|
225 |
until:nil] retain]; |
|
226 |
if (sharingAccount) |
|
227 |
[accountRequest setRequestUserFromDefaultTo:sharingAccount]; |
|
228 |
accountRequest.delegate = self; |
|
229 |
accountRequest.didFinishSelector = @selector(accountRequestFinished:); |
|
230 |
accountRequest.didFailSelector = @selector(accountRequestFailed:); |
|
231 |
accountRequest.userInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys: |
|
232 |
[NSNumber numberWithUnsignedInteger:10], @"retries", |
|
233 |
nil]; |
|
234 |
if (!forcedRefresh) |
|
235 |
accountRequest.downloadCache = [ASIDownloadCache sharedCache]; |
|
236 |
[[PithosUtilities prepareRequest:accountRequest priority:NSOperationQueuePriorityVeryHigh] startAsynchronous]; |
|
173 | 237 |
} |
174 |
// Else cache was used and all results were fetched during this request, so existing children can be reused |
|
238 |
} else if (accountRequest.responseStatusCode == 304) { |
|
239 |
// Account is not modified, so existing children can be reused |
|
175 | 240 |
[accountRequest release]; |
176 | 241 |
accountRequest = nil; |
177 | 242 |
[containers release]; |
... | ... | |
183 | 248 |
// Notify observers that children are updated |
184 | 249 |
[[NSNotificationCenter defaultCenter] postNotificationName:@"PithosAccountNodeChildrenUpdated" object:self]; |
185 | 250 |
} else { |
186 |
[accountRequest release]; |
|
187 |
// Do an additional request to fetch more objects |
|
188 |
accountRequest = [[ASIPithosAccountRequest listContainersRequestWithLimit:0 |
|
189 |
marker:[[someContainers lastObject] name] |
|
190 |
shared:shared |
|
191 |
until:nil] retain]; |
|
192 |
if (sharingAccount) |
|
193 |
[accountRequest setRequestUserFromDefaultTo:sharingAccount]; |
|
194 |
accountRequest.delegate = self; |
|
195 |
if (!forcedRefresh) |
|
196 |
accountRequest.downloadCache = [ASIDownloadCache sharedCache]; |
|
197 |
[[PithosUtilities prepareRequest:accountRequest priority:NSOperationQueuePriorityVeryHigh] startAsynchronous]; |
|
198 |
} |
|
199 |
} |
|
200 |
|
|
201 |
- (void)accountRequestFailed:(ASIPithosAccountRequest *)request { |
|
202 |
[PithosUtilities httpRequestErrorAlertWithRequest:request]; |
|
203 |
[newChildren release]; |
|
204 |
newChildren = nil; |
|
205 |
[accountRequest release]; |
|
206 |
accountRequest = nil; |
|
207 |
[containers release]; |
|
208 |
containers = nil; |
|
209 |
forcedRefresh = NO; |
|
210 |
@synchronized(self) { |
|
211 |
freshness = PithosNodeStateRefreshNeeded; |
|
251 |
[self accountRequestFailed:accountRequest]; |
|
212 | 252 |
} |
213 | 253 |
} |
214 | 254 |
|
b/pithos-macos/PithosContainerNode.m | ||
---|---|---|
44 | 44 |
#import "ASIDownloadCache.h" |
45 | 45 |
#import "PithosUtilities.h" |
46 | 46 |
#import "PithosContainerNodeInfoController.h" |
47 |
#import "PithosActivityFacility.h" |
|
47 | 48 |
|
48 | 49 |
static NSImage *sharedIcon = nil; |
49 | 50 |
|
... | ... | |
132 | 133 |
containerRequest.delegate = self; |
133 | 134 |
containerRequest.didFinishSelector = @selector(containerRequestFinished:); |
134 | 135 |
containerRequest.didFailSelector = @selector(containerRequestFailed:); |
136 |
containerRequest.userInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys: |
|
137 |
[NSNumber numberWithUnsignedInteger:10], @"retries", |
|
138 |
nil]; |
|
135 | 139 |
if (!forcedRefresh) |
136 | 140 |
containerRequest.downloadCache = [ASIDownloadCache sharedCache]; |
137 | 141 |
[[PithosUtilities prepareRequest:containerRequest priority:NSOperationQueuePriorityVeryHigh] startAsynchronous]; |
... | ... | |
188 | 192 |
#pragma mark - |
189 | 193 |
#pragma mark ASIHTTPRequestDelegate |
190 | 194 |
|
191 |
- (void)containerRequestFinished:(ASIPithosContainerRequest *)request { |
|
192 |
NSLog(@"URL: %@", [containerRequest url]); |
|
193 |
NSLog(@"cached: %d", [containerRequest didUseCachedResponse]); |
|
194 |
|
|
195 |
if ((pithosContainer.blockHash == nil) || (pithosContainer.blockSize == 0)) { |
|
196 |
pithosContainer.blockHash = [containerRequest blockHash]; |
|
197 |
pithosContainer.blockSize = [containerRequest blockSize]; |
|
198 |
} |
|
199 |
|
|
200 |
NSArray *someObjects = [containerRequest objects]; |
|
201 |
if (objects == nil) { |
|
202 |
objects = [[NSMutableArray alloc] initWithArray:someObjects]; |
|
195 |
- (void)containerRequestFailed:(ASIPithosContainerRequest *)request { |
|
196 |
NSUInteger retries = [[containerRequest.userInfo objectForKey:@"retries"] unsignedIntegerValue]; |
|
197 |
if (retries > 0) { |
|
198 |
ASIPithosContainerRequest *newContainerRequest = (ASIPithosContainerRequest *)[PithosUtilities copyRequest:containerRequest]; |
|
199 |
[(NSMutableDictionary *)(newContainerRequest.userInfo)setObject:[NSNumber numberWithUnsignedInteger:(--retries)] forKey:@"retries"]; |
|
200 |
[containerRequest release]; |
|
201 |
containerRequest = newContainerRequest; |
|
202 |
[[PithosUtilities prepareRequest:containerRequest priority:NSOperationQueuePriorityVeryHigh] startAsynchronous]; |
|
203 | 203 |
} else { |
204 |
[objects addObjectsFromArray:someObjects]; |
|
204 |
NSString *message; |
|
205 |
NSError *error = [containerRequest error]; |
|
206 |
if (error) |
|
207 |
message = [NSString stringWithFormat:@"Container listing failed: %@", error]; |
|
208 |
else |
|
209 |
message = [NSString stringWithFormat:@"Container listing failed: (%d) %@", |
|
210 |
containerRequest.responseStatusCode, containerRequest.responseStatusMessage]; |
|
211 |
[[PithosActivityFacility defaultPithosActivityFacility] startAndEndActivityWithType:PithosActivityOther message:message]; |
|
212 |
[newChildren release]; |
|
213 |
newChildren = nil; |
|
214 |
[containerRequest release]; |
|
215 |
containerRequest = nil; |
|
216 |
[objects release]; |
|
217 |
objects = nil; |
|
218 |
forcedRefresh = NO; |
|
219 |
@synchronized(self) { |
|
220 |
freshness = PithosNodeStateRefreshNeeded; |
|
221 |
} |
|
205 | 222 |
} |
206 |
if ([someObjects count] < 10000) { |
|
207 |
if (!containerRequest.didUseCachedResponse || ([objects count] != [someObjects count]) || !children) { |
|
208 |
// Save new children |
|
209 |
NSLog(@"using newChildren"); |
|
210 |
newChildren = [[NSMutableArray alloc] init]; |
|
211 |
NSArray *objectNames = [objects valueForKey:@"name"]; |
|
212 |
NSMutableIndexSet *keptNodes = [NSMutableIndexSet indexSet]; |
|
213 |
BOOL isSubdirNode = ([self class] == [PithosSubdirNode class]); |
|
214 |
for (ASIPithosObject *object in objects) { |
|
215 |
if (!isSubdirNode || |
|
216 |
[object.name hasPrefix:[((PithosSubdirNode *)self).prefix stringByAppendingString:@"/"]]) { |
|
217 |
// The check above removes false objects due to trailing slash or same prefix |
|
218 |
if (object.subdir) { |
|
219 |
NSUInteger sameNameObjectIndex = [objectNames indexOfObject:[object.name substringToIndex:([object.name length] - 1)]]; |
|
220 |
if ((sameNameObjectIndex == NSNotFound) || |
|
221 |
![PithosUtilities isContentTypeDirectory:[[objects objectAtIndex:sameNameObjectIndex] contentType]]) { |
|
223 |
} |
|
224 |
|
|
225 |
- (void)containerRequestFinished:(ASIPithosContainerRequest *)request { |
|
226 |
NSLog(@"List container finished: %@", [containerRequest url]); |
|
227 |
NSLog(@"Cached: %d", [containerRequest didUseCachedResponse]); |
|
228 |
if (containerRequest.responseStatusCode == 200) { |
|
229 |
if ((pithosContainer.blockHash == nil) || (pithosContainer.blockSize == 0)) { |
|
230 |
pithosContainer.blockHash = [containerRequest blockHash]; |
|
231 |
pithosContainer.blockSize = [containerRequest blockSize]; |
|
232 |
} |
|
233 |
|
|
234 |
NSArray *someObjects = [containerRequest objects]; |
|
235 |
if (objects == nil) { |
|
236 |
objects = [[NSMutableArray alloc] initWithArray:someObjects]; |
|
237 |
} else { |
|
238 |
[objects addObjectsFromArray:someObjects]; |
|
239 |
} |
|
240 |
if ([someObjects count] < 10000) { |
|
241 |
if (!containerRequest.didUseCachedResponse || ([objects count] != [someObjects count]) || !children) { |
|
242 |
// Save new children |
|
243 |
NSLog(@"using newChildren"); |
|
244 |
newChildren = [[NSMutableArray alloc] init]; |
|
245 |
NSArray *objectNames = [objects valueForKey:@"name"]; |
|
246 |
NSMutableIndexSet *keptNodes = [NSMutableIndexSet indexSet]; |
|
247 |
BOOL isSubdirNode = ([self class] == [PithosSubdirNode class]); |
|
248 |
for (ASIPithosObject *object in objects) { |
|
249 |
if (!isSubdirNode || |
|
250 |
[object.name hasPrefix:[((PithosSubdirNode *)self).prefix stringByAppendingString:@"/"]]) { |
|
251 |
// The check above removes false objects due to trailing slash or same prefix |
|
252 |
if (object.subdir) { |
|
253 |
NSUInteger sameNameObjectIndex = [objectNames indexOfObject:[object.name substringToIndex:([object.name length] - 1)]]; |
|
254 |
if ((sameNameObjectIndex == NSNotFound) || |
|
255 |
![PithosUtilities isContentTypeDirectory:[[objects objectAtIndex:sameNameObjectIndex] contentType]]) { |
|
256 |
PithosSubdirNode *node = [[[PithosSubdirNode alloc] initWithPithosContainer:pithosContainer pithosObject:object] autorelease]; |
|
257 |
node.parent = self; |
|
258 |
node.shared = shared; |
|
259 |
node.sharingAccount = sharingAccount; |
|
260 |
if (children) { |
|
261 |
NSUInteger oldIndex = [children indexOfObject:node]; |
|
262 |
if (oldIndex != NSNotFound) { |
|
263 |
// Use the same pointer value, if possible |
|
264 |
node = [children objectAtIndex:oldIndex]; |
|
265 |
node.pithosContainer = pithosContainer; |
|
266 |
node.pithosObject = object; |
|
267 |
[keptNodes addIndex:oldIndex]; |
|
268 |
} |
|
269 |
} |
|
270 |
if (sharingAccount) |
|
271 |
node.pithosObject.allowedTo = [NSString stringWithString:@"read"]; |
|
272 |
[newChildren addObject:node]; |
|
273 |
} |
|
274 |
} else if ([PithosUtilities isContentTypeDirectory:object.contentType]) { |
|
222 | 275 |
PithosSubdirNode *node = [[[PithosSubdirNode alloc] initWithPithosContainer:pithosContainer pithosObject:object] autorelease]; |
223 | 276 |
node.parent = self; |
224 | 277 |
node.shared = shared; |
... | ... | |
233 | 286 |
[keptNodes addIndex:oldIndex]; |
234 | 287 |
} |
235 | 288 |
} |
236 |
if (sharingAccount) |
|
237 |
node.pithosObject.allowedTo = [NSString stringWithString:@"read"]; |
|
238 | 289 |
[newChildren addObject:node]; |
239 |
} |
|
240 |
} else if ([PithosUtilities isContentTypeDirectory:object.contentType]) { |
|
241 |
PithosSubdirNode *node = [[[PithosSubdirNode alloc] initWithPithosContainer:pithosContainer pithosObject:object] autorelease]; |
|
242 |
node.parent = self; |
|
243 |
node.shared = shared; |
|
244 |
node.sharingAccount = sharingAccount; |
|
245 |
if (children) { |
|
246 |
NSUInteger oldIndex = [children indexOfObject:node]; |
|
247 |
if (oldIndex != NSNotFound) { |
|
248 |
// Use the same pointer value, if possible |
|
249 |
node = [children objectAtIndex:oldIndex]; |
|
250 |
node.pithosContainer = pithosContainer; |
|
251 |
node.pithosObject = object; |
|
252 |
[keptNodes addIndex:oldIndex]; |
|
253 |
} |
|
254 |
} |
|
255 |
[newChildren addObject:node]; |
|
256 |
} else { |
|
257 |
PithosObjectNode *node = [[[PithosObjectNode alloc] initWithPithosContainer:pithosContainer pithosObject:object] autorelease]; |
|
258 |
node.parent = self; |
|
259 |
node.shared = shared; |
|
260 |
node.sharingAccount = sharingAccount; |
|
261 |
if (children) { |
|
262 |
NSUInteger oldIndex = [children indexOfObject:node]; |
|
263 |
if (oldIndex != NSNotFound) { |
|
264 |
// Use the same pointer value, if possible |
|
265 |
node = [children objectAtIndex:oldIndex]; |
|
266 |
node.pithosContainer = pithosContainer; |
|
267 |
node.pithosObject = object; |
|
268 |
[keptNodes addIndex:oldIndex]; |
|
290 |
} else { |
|
291 |
PithosObjectNode *node = [[[PithosObjectNode alloc] initWithPithosContainer:pithosContainer pithosObject:object] autorelease]; |
|
292 |
node.parent = self; |
|
293 |
node.shared = shared; |
|
294 |
node.sharingAccount = sharingAccount; |
|
295 |
if (children) { |
|
296 |
NSUInteger oldIndex = [children indexOfObject:node]; |
|
297 |
if (oldIndex != NSNotFound) { |
|
298 |
// Use the same pointer value, if possible |
|
299 |
node = [children objectAtIndex:oldIndex]; |
|
300 |
node.pithosContainer = pithosContainer; |
|
301 |
node.pithosObject = object; |
|
302 |
[keptNodes addIndex:oldIndex]; |
|
303 |
} |
|
269 | 304 |
} |
305 |
[newChildren addObject:node]; |
|
270 | 306 |
} |
271 |
[newChildren addObject:node]; |
|
272 | 307 |
} |
273 | 308 |
} |
309 |
[[children objectsAtIndexes: |
|
310 |
[[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, [children count])] indexesPassingTest:^(NSUInteger idx, BOOL *stop){ |
|
311 |
if ([keptNodes containsIndex:idx]) |
|
312 |
return NO; |
|
313 |
return YES; |
|
314 |
}]] makeObjectsPerformSelector:@selector(pithosNodeWillBeRemoved)]; |
|
315 |
} |
|
316 |
// Else cache was used and all results were fetched during this request, so existing children can be reused |
|
317 |
[containerRequest release]; |
|
318 |
containerRequest = nil; |
|
319 |
[objects release]; |
|
320 |
objects = nil; |
|
321 |
forcedRefresh = NO; |
|
322 |
@synchronized(self) { |
|
323 |
freshness = PithosNodeStateRefreshFinished; |
|
274 | 324 |
} |
275 |
[[children objectsAtIndexes: |
|
276 |
[[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, [children count])] indexesPassingTest:^(NSUInteger idx, BOOL *stop){ |
|
277 |
if ([keptNodes containsIndex:idx]) |
|
278 |
return NO; |
|
279 |
return YES; |
|
280 |
}]] makeObjectsPerformSelector:@selector(pithosNodeWillBeRemoved)]; |
|
325 |
// Notify observers that children are updated |
|
326 |
[[NSNotificationCenter defaultCenter] postNotificationName:childrenUpdatedNotificationName object:self]; |
|
327 |
} else { |
|
328 |
[containerRequest release]; |
|
329 |
// Do an additional request to fetch more objects |
|
330 |
containerRequest = [[ASIPithosContainerRequest listObjectsRequestWithContainerName:pithosContainer.name |
|
331 |
limit:0 |
|
332 |
marker:[[someObjects lastObject] name] |
|
333 |
prefix:prefix |
|
334 |
delimiter:@"/" |
|
335 |
path:nil |
|
336 |
meta:nil |
|
337 |
shared:shared |
|
338 |
until:nil] retain]; |
|
339 |
if (sharingAccount) |
|
340 |
[containerRequest setRequestUserFromDefaultTo:sharingAccount]; |
|
341 |
containerRequest.delegate = self; |
|
342 |
containerRequest.didFinishSelector = @selector(containerRequestFinished:); |
|
343 |
containerRequest.didFailSelector = @selector(containerRequestFailed:); |
|
344 |
containerRequest.userInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys: |
|
345 |
[NSNumber numberWithUnsignedInteger:10], @"retries", |
|
346 |
nil]; |
|
347 |
if (!forcedRefresh) |
|
348 |
containerRequest.downloadCache = [ASIDownloadCache sharedCache]; |
|
349 |
[[PithosUtilities prepareRequest:containerRequest priority:NSOperationQueuePriorityVeryHigh] startAsynchronous]; |
|
281 | 350 |
} |
282 |
// Else cache was used and all results were fetched during this request, so existing children can be reused |
|
351 |
} else if (containerRequest.responseStatusCode == 304) { |
|
352 |
// Container is not modified, so existing children can be reused |
|
283 | 353 |
[containerRequest release]; |
284 | 354 |
containerRequest = nil; |
285 | 355 |
[objects release]; |
... | ... | |
291 | 361 |
// Notify observers that children are updated |
292 | 362 |
[[NSNotificationCenter defaultCenter] postNotificationName:childrenUpdatedNotificationName object:self]; |
293 | 363 |
} else { |
294 |
[containerRequest release]; |
|
295 |
// Do an additional request to fetch more objects |
|
296 |
containerRequest = [[ASIPithosContainerRequest listObjectsRequestWithContainerName:pithosContainer.name |
|
297 |
limit:0 |
|
298 |
marker:[[someObjects lastObject] name] |
|
299 |
prefix:prefix |
|
300 |
delimiter:@"/" |
|
301 |
path:nil |
|
302 |
meta:nil |
|
303 |
shared:shared |
|
304 |
until:nil] retain]; |
|
305 |
if (sharingAccount) |
|
306 |
[containerRequest setRequestUserFromDefaultTo:sharingAccount]; |
|
307 |
containerRequest.delegate = self; |
|
308 |
if (!forcedRefresh) |
|
309 |
containerRequest.downloadCache = [ASIDownloadCache sharedCache]; |
|
310 |
[[PithosUtilities prepareRequest:containerRequest priority:NSOperationQueuePriorityVeryHigh] startAsynchronous]; |
|
311 |
} |
|
312 |
} |
|
313 |
|
|
314 |
- (void)containerRequestFailed:(ASIPithosContainerRequest *)request { |
|
315 |
[PithosUtilities httpRequestErrorAlertWithRequest:request]; |
|
316 |
[newChildren release]; |
|
317 |
newChildren = nil; |
|
318 |
[containerRequest release]; |
|
319 |
containerRequest = nil; |
|
320 |
[objects release]; |
|
321 |
objects = nil; |
|
322 |
forcedRefresh = NO; |
|
323 |
@synchronized(self) { |
|
324 |
freshness = PithosNodeStateRefreshNeeded; |
|
364 |
[self containerRequestFailed:containerRequest]; |
|
325 | 365 |
} |
326 | 366 |
} |
327 | 367 |
|
b/pithos-macos/PithosSharingAccountsNode.m | ||
---|---|---|
41 | 41 |
#import "ASIPithosAccount.h" |
42 | 42 |
#import "ASIDownloadCache.h" |
43 | 43 |
#import "PithosUtilities.h" |
44 |
#import "PithosActivityFacility.h" |
|
44 | 45 |
|
45 | 46 |
@implementation PithosSharingAccountsNode |
46 | 47 |
|
... | ... | |
82 | 83 |
sharingAccountsRequest.delegate = self; |
83 | 84 |
sharingAccountsRequest.didFinishSelector = @selector(sharingAccountsRequestFinished:); |
84 | 85 |
sharingAccountsRequest.didFailSelector = @selector(sharingAccountsRequestFailed:); |
86 |
sharingAccountsRequest.userInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys: |
|
87 |
[NSNumber numberWithUnsignedInteger:10], @"retries", |
|
88 |
nil]; |
|
85 | 89 |
if (!forcedRefresh) |
86 | 90 |
sharingAccountsRequest.downloadCache = [ASIDownloadCache sharedCache]; |
87 | 91 |
[[PithosUtilities prepareRequest:sharingAccountsRequest priority:NSOperationQueuePriorityVeryHigh] startAsynchronous]; |
... | ... | |
111 | 115 |
#pragma mark - |
112 | 116 |
#pragma mark ASIHTTPRequestDelegate |
113 | 117 |
|
114 |
- (void)sharingAccountsRequestFinished:(ASIPithosRequest *)request { |
|
115 |
NSLog(@"URL: %@", [sharingAccountsRequest url]); |
|
116 |
NSLog(@"cached: %d", [sharingAccountsRequest didUseCachedResponse]); |
|
117 |
|
|
118 |
NSArray *someSharingAccounts = [sharingAccountsRequest sharingAccounts]; |
|
119 |
if (sharingAccounts == nil) { |
|
120 |
sharingAccounts = [[NSMutableArray alloc] initWithArray:someSharingAccounts]; |
|
118 |
- (void)sharingAccountsRequestFailed:(ASIPithosRequest *)request { |
|
119 |
NSUInteger retries = [[sharingAccountsRequest.userInfo objectForKey:@"retries"] unsignedIntegerValue]; |
|
120 |
if (retries > 0) { |
|
121 |
ASIPithosRequest *newSharingAccountsRequest = (ASIPithosRequest *)[PithosUtilities copyRequest:sharingAccountsRequest]; |
|
122 |
[(NSMutableDictionary *)(newSharingAccountsRequest.userInfo)setObject:[NSNumber numberWithUnsignedInteger:(--retries)] forKey:@"retries"]; |
|
123 |
[sharingAccountsRequest release]; |
|
124 |
sharingAccountsRequest = newSharingAccountsRequest; |
|
125 |
[[PithosUtilities prepareRequest:sharingAccountsRequest priority:NSOperationQueuePriorityVeryHigh] startAsynchronous]; |
|
121 | 126 |
} else { |
122 |
[sharingAccounts addObjectsFromArray:someSharingAccounts]; |
|
123 |
} |
|
124 |
if ([someSharingAccounts count] < 10000) { |
|
125 |
if (!sharingAccountsRequest.didUseCachedResponse || ([sharingAccounts count] != [someSharingAccounts count]) || !children) { |
|
126 |
// Save new children |
|
127 |
NSLog(@"using newChildren"); |
|
128 |
newChildren = [[NSMutableArray alloc] init]; |
|
129 |
NSMutableIndexSet *keptNodes = [NSMutableIndexSet indexSet]; |
|
130 |
for (ASIPithosAccount *account in sharingAccounts) { |
|
131 |
if (![account.name isEqualToString:[ASIPithosRequest authUser]]) { |
|
132 |
PithosAccountNode *node = [[[PithosAccountNode alloc] init] autorelease]; |
|
133 |
node.parent = self; |
|
134 |
node.shared = shared; |
|
135 |
node.sharingAccount = account.name; |
|
136 |
if (children) { |
|
137 |
NSUInteger oldIndex = [children indexOfObject:node]; |
|
138 |
if (oldIndex != NSNotFound) { |
|
139 |
// Use the same pointer value, if possible |
|
140 |
node = [children objectAtIndex:oldIndex]; |
|
141 |
[keptNodes addIndex:oldIndex]; |
|
142 |
} |
|
143 |
} |
|
144 |
[newChildren addObject:node]; |
|
145 |
} |
|
146 |
} |
|
147 |
[[children objectsAtIndexes: |
|
148 |
[[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, [children count])] indexesPassingTest:^(NSUInteger idx, BOOL *stop){ |
|
149 |
if ([keptNodes containsIndex:idx]) |
|
150 |
return NO; |
|
151 |
return YES; |
|
152 |
}]] makeObjectsPerformSelector:@selector(pithosNodeWillBeRemoved)]; |
|
153 |
} |
|
154 |
// Else cache was used and all results were fetched during this request, so existing children can be reused |
|
127 |
NSString *message; |
|
128 |
NSError *error = [sharingAccountsRequest error]; |
|
129 |
if (error) |
|
130 |
message = [NSString stringWithFormat:@"Sharing accounts listing failed: %@", error]; |
|
131 |
else |
|
132 |
message = [NSString stringWithFormat:@"Sharing accounts listing failed: (%d) %@", |
|
133 |
sharingAccountsRequest.responseStatusCode, sharingAccountsRequest.responseStatusMessage]; |
|
134 |
[[PithosActivityFacility defaultPithosActivityFacility] startAndEndActivityWithType:PithosActivityOther message:message]; |
|
135 |
[newChildren release]; |
|
136 |
newChildren = nil; |
|
155 | 137 |
[sharingAccountsRequest release]; |
156 | 138 |
sharingAccountsRequest = nil; |
157 | 139 |
[sharingAccounts release]; |
158 | 140 |
sharingAccounts = nil; |
159 | 141 |
forcedRefresh = NO; |
160 | 142 |
@synchronized(self) { |
161 |
freshness = PithosNodeStateRefreshFinished;
|
|
143 |
freshness = PithosNodeStateRefreshNeeded;
|
|
162 | 144 |
} |
163 |
// Notify observers that children are updated |
|
164 |
[[NSNotificationCenter defaultCenter] postNotificationName:@"PithosSharingAccountsNodeChildrenUpdated" object:self]; |
|
165 |
} else { |
|
166 |
[sharingAccountsRequest release]; |
|
167 |
// Do an additional request to fetch more objects |
|
168 |
sharingAccountsRequest = [[ASIPithosRequest listSharingAccountsRequestWithLimit:0 |
|
169 |
marker:[[someSharingAccounts lastObject] name]] retain]; |
|
170 |
sharingAccountsRequest.delegate = self; |
|
171 |
if (!forcedRefresh) |
|
172 |
sharingAccountsRequest.downloadCache = [ASIDownloadCache sharedCache]; |
|
173 |
[[PithosUtilities prepareRequest:sharingAccountsRequest priority:NSOperationQueuePriorityVeryHigh] startAsynchronous]; |
|
174 | 145 |
} |
175 | 146 |
} |
176 | 147 |
|
177 |
- (void)accountRequestFailed:(ASIPithosRequest *)request { |
|
178 |
[PithosUtilities httpRequestErrorAlertWithRequest:request]; |
|
179 |
[newChildren release]; |
|
180 |
newChildren = nil; |
|
181 |
[sharingAccountsRequest release]; |
|
182 |
sharingAccountsRequest = nil; |
|
183 |
[sharingAccounts release]; |
|
184 |
sharingAccounts = nil; |
|
185 |
forcedRefresh = NO; |
|
186 |
@synchronized(self) { |
|
187 |
freshness = PithosNodeStateRefreshNeeded; |
|
148 |
- (void)sharingAccountsRequestFinished:(ASIPithosRequest *)request { |
|
149 |
NSLog(@"List sharing accounts finished: %@", [sharingAccountsRequest url]); |
|
150 |
NSLog(@"Cached: %d", [sharingAccountsRequest didUseCachedResponse]); |
|
151 |
if (sharingAccountsRequest.responseStatusCode == 200) { |
|
152 |
NSArray *someSharingAccounts = [sharingAccountsRequest sharingAccounts]; |
|
153 |
if (sharingAccounts == nil) { |
|
154 |
sharingAccounts = [[NSMutableArray alloc] initWithArray:someSharingAccounts]; |
|
155 |
} else { |
|
156 |
[sharingAccounts addObjectsFromArray:someSharingAccounts]; |
|
157 |
} |
|
158 |
if ([someSharingAccounts count] < 10000) { |
|
159 |
if (!sharingAccountsRequest.didUseCachedResponse || ([sharingAccounts count] != [someSharingAccounts count]) || !children) { |
|
160 |
// Save new children |
|
161 |
NSLog(@"using newChildren"); |
|
162 |
newChildren = [[NSMutableArray alloc] init]; |
|
163 |
NSMutableIndexSet *keptNodes = [NSMutableIndexSet indexSet]; |
|
164 |
for (ASIPithosAccount *account in sharingAccounts) { |
|
165 |
if (![account.name isEqualToString:[ASIPithosRequest authUser]]) { |
|
166 |
PithosAccountNode *node = [[[PithosAccountNode alloc] init] autorelease]; |
|
167 |
node.parent = self; |
|
168 |
node.shared = shared; |
|
169 |
node.sharingAccount = account.name; |
|
170 |
if (children) { |
|
171 |
NSUInteger oldIndex = [children indexOfObject:node]; |
|
172 |
if (oldIndex != NSNotFound) { |
|
173 |
// Use the same pointer value, if possible |
|
174 |
node = [children objectAtIndex:oldIndex]; |
|
175 |
[keptNodes addIndex:oldIndex]; |
|
176 |
} |
|
177 |
} |
|
178 |
[newChildren addObject:node]; |
|
179 |
} |
|
180 |
} |
|
181 |
[[children objectsAtIndexes: |
|
182 |
[[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, [children count])] indexesPassingTest:^(NSUInteger idx, BOOL *stop){ |
|
183 |
if ([keptNodes containsIndex:idx]) |
|
184 |
return NO; |
|
185 |
return YES; |
|
186 |
}]] makeObjectsPerformSelector:@selector(pithosNodeWillBeRemoved)]; |
|
187 |
} |
|
188 |
// Else cache was used and all results were fetched during this request, so existing children can be reused |
|
189 |
[sharingAccountsRequest release]; |
|
190 |
sharingAccountsRequest = nil; |
|
191 |
[sharingAccounts release]; |
|
192 |
sharingAccounts = nil; |
|
193 |
forcedRefresh = NO; |
|
194 |
@synchronized(self) { |
|
195 |
freshness = PithosNodeStateRefreshFinished; |
|
196 |
} |
|
197 |
// Notify observers that children are updated |
|
198 |
[[NSNotificationCenter defaultCenter] postNotificationName:@"PithosSharingAccountsNodeChildrenUpdated" object:self]; |
|
199 |
} else { |
|
200 |
[sharingAccountsRequest release]; |
|
201 |
// Do an additional request to fetch more objects |
|
202 |
sharingAccountsRequest = [[ASIPithosRequest listSharingAccountsRequestWithLimit:0 |
|
203 |
marker:[[someSharingAccounts lastObject] name]] retain]; |
|
204 |
sharingAccountsRequest.delegate = self; |
|
205 |
sharingAccountsRequest.didFinishSelector = @selector(sharingAccountsRequestFinished:); |
|
206 |
sharingAccountsRequest.didFailSelector = @selector(sharingAccountsRequestFailed:); |
|
207 |
sharingAccountsRequest.userInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys: |
|
208 |
[NSNumber numberWithUnsignedInteger:10], @"retries", |
|
209 |
nil]; |
|
210 |
if (!forcedRefresh) |
|
211 |
sharingAccountsRequest.downloadCache = [ASIDownloadCache sharedCache]; |
|
212 |
[[PithosUtilities prepareRequest:sharingAccountsRequest priority:NSOperationQueuePriorityVeryHigh] startAsynchronous]; |
|
213 |
} |
|
214 |
} else { |
|
215 |
[self sharingAccountsRequestFailed:sharingAccountsRequest]; |
|
188 | 216 |
} |
189 | 217 |
} |
190 | 218 |
|
Also available in: Unified diff