Merge lp:~threeve/ubuntuone-ios-files/fix-upload-failure-node-deletion into lp:ubuntuone-ios-files

Proposed by Jason Foreman
Status: Merged
Merged at revision: 24
Proposed branch: lp:~threeve/ubuntuone-ios-files/fix-upload-failure-node-deletion
Merge into: lp:ubuntuone-ios-files
Diff against target: 284 lines (+60/-39)
8 files modified
Files/Files-Info.plist (+1/-1)
Files/FilesAppDelegate.m (+11/-2)
Files/U1AutoUploadOperation.m (+8/-13)
Files/U1AutoUploadsManager.m (+8/-4)
Files/U1FilesClient.m (+0/-1)
Files/U1FolderViewController.m (+10/-1)
Files/U1SettingsViewController.m (+4/-4)
Files/U1UploadOperation.m (+18/-13)
To merge this branch: bzr merge lp:~threeve/ubuntuone-ios-files/fix-upload-failure-node-deletion
Reviewer Review Type Date Requested Status
Zachery Bir Approve
Review via email: mp+84546@code.launchpad.net

Description of the change

Fix some bugs with auto uploading, particularly when concerning deleted nodes.

To post a comment you must log in.
Revision history for this message
Zachery Bir (urbanape) wrote :

Go for it

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Files/Files-Info.plist'
2--- Files/Files-Info.plist 2011-12-02 19:51:31 +0000
3+++ Files/Files-Info.plist 2011-12-06 02:01:27 +0000
4@@ -41,7 +41,7 @@
5 <key>CFBundleSignature</key>
6 <string>????</string>
7 <key>CFBundleVersion</key>
8- <string>21</string>
9+ <string>23</string>
10 <key>LSRequiresIPhoneOS</key>
11 <true/>
12 <key>NSMainNibFile</key>
13
14=== modified file 'Files/FilesAppDelegate.m'
15--- Files/FilesAppDelegate.m 2011-12-01 20:12:23 +0000
16+++ Files/FilesAppDelegate.m 2011-12-06 02:01:27 +0000
17@@ -91,15 +91,25 @@
18 {
19 [self showVolumes];
20 }
21+
22+ // XXX: Remove this later, some users still have an app icon badge set
23+ [[UIApplication sharedApplication] setApplicationIconBadgeNumber:nil];
24
25 return YES;
26 }
27
28+- (void)applicationDidBecomeActive:(UIApplication *)application;
29+{
30+ if (![[U1AccountManager sharedAccountManager] hasCredentials])
31+ {
32+ [self showLoginController];
33+ }
34+}
35+
36 - (void)applicationWillResignActive:(UIApplication *)application;
37 {
38 [self.dataRepository save:NULL];
39 [[NSUserDefaults standardUserDefaults] synchronize];
40- [[UIApplication sharedApplication] setApplicationIconBadgeNumber:[self.filesClient queueCount]];
41 [[UIApplication sharedApplication] setIdleTimerDisabled:NO];
42 }
43
44@@ -108,7 +118,6 @@
45 // TODO: check error
46 [self.dataRepository save:NULL];
47 [[NSUserDefaults standardUserDefaults] synchronize];
48- [[UIApplication sharedApplication] setApplicationIconBadgeNumber:[self.filesClient queueCount]];
49 [[UIApplication sharedApplication] setIdleTimerDisabled:NO];
50 }
51
52
53=== modified file 'Files/U1AutoUploadOperation.m'
54--- Files/U1AutoUploadOperation.m 2011-11-30 21:42:52 +0000
55+++ Files/U1AutoUploadOperation.m 2011-12-06 02:01:27 +0000
56@@ -43,7 +43,6 @@
57 self.executing = NO;
58 [self didChangeValueForKey:@"isFinished"];
59 [self didChangeValueForKey:@"isExecuting"];
60- // [UONetworkStatusCoordinator removeNetworkActivity];
61 }
62
63 - (void)start;
64@@ -70,22 +69,18 @@
65 dispatch_async(dispatch_get_main_queue(), ^(void) {
66 [[U1FilesClient sharedFilesClient] uploadContentDataProvider:dataProvider toFolder:self.folder withResourceName:self.filename withContentType:self.contentType withPriority:self.priority progressBlock:^(long long bytesUploaded, long long totalBytes) {
67
68-// NSLog(@"progress!");
69-
70 } completionBlock:^(U1FileNode *fileNode, NSError *error) {
71- if (error == nil)
72- {
73- dispatch_async(dispatch_get_main_queue(), ^(void) {
74- self.u1asset.generation = self.u1asset.fileNode.generation;
75- [[U1DataRepository sharedDataRepository] save:NULL];
76- [self finishExecuting];
77- });
78- }
79- else
80+ if (error)
81 {
82 NSLog(@"auto-upload failed: %@", error);
83- [self beginUpload];
84 }
85+
86+ dispatch_async(dispatch_get_main_queue(), ^(void) {
87+
88+ self.u1asset.generation = self.u1asset.fileNode.generation;
89+ [[U1DataRepository sharedDataRepository] save:NULL];
90+ [self finishExecuting];
91+ });
92 }];
93 });
94 }
95
96=== modified file 'Files/U1AutoUploadsManager.m'
97--- Files/U1AutoUploadsManager.m 2011-12-02 19:20:54 +0000
98+++ Files/U1AutoUploadsManager.m 2011-12-06 02:01:27 +0000
99@@ -181,9 +181,13 @@
100 // fetch the remote upload folder contents, and stash the children objects somewhere locally.
101 [self.filesClient fetchFolderWithResourcePath:self.remoteUploadFolder.resourcePath
102 resultsBlock:^(U1Node *node, NSFetchedResultsController *childrenResultsController, U1DataSourceType resultsDataSourceType) {
103- [childrenResultsController performFetch:NULL];
104- [self queuePreviousUploads];
105- [self checkForNewAssets];
106+
107+ if (resultsDataSourceType == U1DataSourceRemote)
108+ {
109+ [childrenResultsController performFetch:NULL];
110+ [self queuePreviousUploads];
111+ [self checkForNewAssets];
112+ }
113 }
114 errorBlock:^(NSError *error) {}];
115 }
116@@ -236,7 +240,7 @@
117
118 dispatch_async(dispatch_get_main_queue(), ^(void) {
119
120- NSPredicate *p = [NSPredicate predicateWithFormat:@"url in %@ and fileNode.parent = %@", URLs, self.remoteUploadFolder];
121+ NSPredicate *p = [NSPredicate predicateWithFormat:@"url in %@ and (fileNode.parent = %@ OR fileNode = nil)", URLs, self.remoteUploadFolder];
122 NSError *error = nil;
123 NSSortDescriptor *sortBy = [NSSortDescriptor sortDescriptorWithKey:@"url" ascending:YES];
124 NSArray *existingU1Assets = [self.dataRepository resultsForEntityClass:[U1Asset class]
125
126=== modified file 'Files/U1FilesClient.m'
127--- Files/U1FilesClient.m 2011-12-02 19:51:14 +0000
128+++ Files/U1FilesClient.m 2011-12-06 02:01:27 +0000
129@@ -379,7 +379,6 @@
130 dispatch_async(dispatch_get_main_queue(), ^(void) {
131 if (operation.error == nil) // or the error is somehow unrecoverable (e.g., over quota)
132 {
133- [[UIApplication sharedApplication] setApplicationIconBadgeNumber:[self queueCount]];
134 [[NSNotificationCenter defaultCenter] postNotificationName:@"imageUploaded" object:nil];
135 completionBlock(operation.fileNode, nil);
136 }
137
138=== modified file 'Files/U1FolderViewController.m'
139--- Files/U1FolderViewController.m 2011-12-02 19:51:14 +0000
140+++ Files/U1FolderViewController.m 2011-12-06 02:01:27 +0000
141@@ -19,6 +19,7 @@
142 #import "U1Asset.h"
143 #import "U1AssetRepresenationDataProvider.h"
144 #import "U1ByteSizeValueTransformer.h"
145+#import "U1DataRepository.h"
146 #import "U1FileNode.h"
147 #import "U1FilesClient.h"
148 #import "U1FolderItemCell.h"
149@@ -244,7 +245,6 @@
150 {
151 U1AssetRepresenationDataProvider *provider = [[U1AssetRepresenationDataProvider alloc] init];
152 provider.representation = representation;
153-
154 dispatch_async(dispatch_get_main_queue(), ^(void) {
155 [self.filesClient uploadContentDataProvider:provider
156 toFolder:self.node
157@@ -253,6 +253,15 @@
158 withPriority:NSOperationQueuePriorityVeryHigh
159 progressBlock:^(long long bytesUploaded, long long totalBytes) {}
160 completionBlock:^(U1FileNode *updatedNode, NSError *error) {
161+
162+ if (error)
163+ {
164+ // TODO: remove direct access to data repository
165+ [[U1DataRepository sharedDataRepository] dispatchBlockWithManagedObjectContext:^(NSManagedObjectContext *context) {
166+ [context deleteObject:u1asset.fileNode];
167+ }];
168+ }
169+
170 u1asset.generation = updatedNode.generation;
171 }];
172 });
173
174=== modified file 'Files/U1SettingsViewController.m'
175--- Files/U1SettingsViewController.m 2011-11-09 20:39:44 +0000
176+++ Files/U1SettingsViewController.m 2011-12-06 02:01:27 +0000
177@@ -174,7 +174,7 @@
178 case U1SettingsViewSectionAccount:
179 return self.accountInfo == nil ? 1 : 2;
180 case U1SettingsViewSectionCameraRoll:
181- return 4; // TODO const
182+ return 3; // TODO const
183 }
184 return 0;
185 }
186@@ -182,7 +182,7 @@
187 - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
188 {
189 if (indexPath.section == U1SettingsViewSectionCameraRoll &&
190- indexPath.row == 3)
191+ indexPath.row == 2)
192 {
193 return 70.0f;
194 }
195@@ -228,8 +228,8 @@
196 {
197 case 0: return [self preparedAutoUploadCell];
198 case 1: return [self preparedWifiOnlyCell];
199- case 2: return [self preparedIncludeVideoCell];
200- case 3: return [self preparedDisableSleepCell];
201+// case 2: return [self preparedIncludeVideoCell];
202+ case 2: return [self preparedDisableSleepCell];
203 default: return nil;
204 }
205 }
206
207=== modified file 'Files/U1UploadOperation.m'
208--- Files/U1UploadOperation.m 2011-12-01 17:37:53 +0000
209+++ Files/U1UploadOperation.m 2011-12-06 02:01:27 +0000
210@@ -27,6 +27,7 @@
211 @property (getter=isExecuting) BOOL executing;
212 @property (getter=isFinished) BOOL finished;
213 - (void)finishExecuting;
214+- (void)beginUpload;
215 @end
216
217
218@@ -42,6 +43,7 @@
219 fileInfo = [[U1LocalFileInfo alloc] init];
220 return self;
221 }
222+
223 - (BOOL)isConcurrent;
224 {
225 return YES;
226@@ -64,25 +66,30 @@
227 self.executing = YES;
228 [self didChangeValueForKey:@"isExecuting"];
229
230- U1FilesService *filesService = [U1FilesService sharedFilesService];
231- U1DataRepository *dataRepository = [U1DataRepository sharedDataRepository];
232+ [self beginUpload];
233+}
234
235- fileInfo.uploading = YES;
236-
237- // if the file already exists at that resourcePath, skip it. In the future, we should do stuff like test that the remote resource's size is the same as our size, and do the right thing accordingly, but I'm not sure what that is right now.
238-
239+- (void)beginUpload;
240+{
241 dispatch_async(dispatch_get_main_queue(), ^(void) {
242+
243+ [self.fileInfo setUploadPercentage:0.0];
244+ [self.fileInfo setUploading:YES];
245+ [self.fileInfo setUploaded:NO];
246+
247+ U1FilesService *filesService = [U1FilesService sharedFilesService];
248+ fileInfo.uploading = YES;
249 NSData *uploadData = [self.dataProvider serializeData];
250-
251+
252 [filesService uploadContentData:uploadData forNode:self.fileNode withContentType:self.mimetype progressBlock:^(long long uploaded, long long totalLength) {
253-
254+
255 dispatch_async(dispatch_get_main_queue(), ^{
256 [self.fileInfo setUploadPercentage:((double)uploaded / (double)totalLength)];
257 });
258
259 if (self.progressBlock)
260 self.progressBlock(uploaded, totalLength);
261-
262+
263 } completionBlock:^(NSDictionary *updatedNodeInfo, NSError *filesServiceError) {
264
265 dispatch_async(dispatch_get_main_queue(), ^{
266@@ -93,16 +100,14 @@
267
268 if (filesServiceError != nil)
269 {
270- [dataRepository dispatchBlockWithManagedObjectContext:^(NSManagedObjectContext *context) {
271- [context deleteObject:self.fileNode];
272- }];
273 self.error = filesServiceError;
274+ [self beginUpload];
275 }
276 else
277 {
278 [self.fileNode updatePropertiesFromJSONDictionary:updatedNodeInfo];
279+ [self finishExecuting];
280 }
281- [self finishExecuting];
282 }];
283 });
284 }

Subscribers

People subscribed via source and target branches