Merge lp:~karni/ubuntuone-android-files/fix-invalidate-cache into lp:ubuntuone-android-files

Proposed by Michał Karnicki
Status: Merged
Merged at revision: 341
Proposed branch: lp:~karni/ubuntuone-android-files/fix-invalidate-cache
Merge into: lp:ubuntuone-android-files
Diff against target: 102 lines (+33/-2)
3 files modified
src/com/ubuntuone/android/files/activity/FilesActivity.java (+3/-0)
src/com/ubuntuone/android/files/service/MetaService.java (+22/-2)
src/com/ubuntuone/android/files/util/TransferUtils.java (+8/-0)
To merge this branch: bzr merge lp:~karni/ubuntuone-android-files/fix-invalidate-cache
Reviewer Review Type Date Requested Status
dobey (community) Approve
Chad Miller Pending
Review via email: mp+106198@code.launchpad.net

Description of the change

Cached files, which generation has changed, get reused by resumable downloads. Once we detect generation change, we remove the file immediately.

Additionally, one commit fixes a problem of queued download, which may have failed and should be freshly rescheduled upon user request.

To post a comment you must log in.
Revision history for this message
dobey (dobey) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/com/ubuntuone/android/files/activity/FilesActivity.java'
2--- src/com/ubuntuone/android/files/activity/FilesActivity.java 2012-04-30 23:32:45 +0000
3+++ src/com/ubuntuone/android/files/activity/FilesActivity.java 2012-05-17 14:15:25 +0000
4@@ -80,6 +80,7 @@
5 import com.ubuntuone.android.files.provider.MetaContract.Nodes;
6 import com.ubuntuone.android.files.provider.MetaContract.ResourceState;
7 import com.ubuntuone.android.files.provider.MetaUtilities;
8+import com.ubuntuone.android.files.provider.TransfersContract.Downloads;
9 import com.ubuntuone.android.files.service.MetaService;
10 import com.ubuntuone.android.files.service.MetaService.Status;
11 import com.ubuntuone.android.files.service.MetaServiceHelper;
12@@ -1403,6 +1404,8 @@
13
14 public void downloadFile(final String resourcePath) {
15 if (NetworkUtil.isConnected(this)) {
16+ TransferUtils.dequeueByResourcePath(getContentResolver(),
17+ Downloads.CONTENT_URI, resourcePath);
18 UpDownServiceHelper.download(this, resourcePath);
19 } else {
20 Toast.makeText(this, "Not connected.", Toast.LENGTH_SHORT).show();
21
22=== modified file 'src/com/ubuntuone/android/files/service/MetaService.java'
23--- src/com/ubuntuone/android/files/service/MetaService.java 2012-04-24 23:15:41 +0000
24+++ src/com/ubuntuone/android/files/service/MetaService.java 2012-05-17 14:15:25 +0000
25@@ -34,6 +34,7 @@
26
27 import org.apache.http.client.HttpClient;
28
29+import android.content.ContentProvider;
30 import android.content.ContentProviderOperation;
31 import android.content.ContentResolver;
32 import android.content.ContentValues;
33@@ -45,6 +46,7 @@
34 import android.os.IBinder;
35 import android.os.RemoteException;
36 import android.os.ResultReceiver;
37+import android.text.TextUtils;
38
39 import com.ubuntuone.android.files.Preferences;
40 import com.ubuntuone.android.files.UbuntuOneFiles;
41@@ -661,8 +663,10 @@
42 new ArrayList<ContentProviderOperation>();
43
44 // Update or insert child nodes.
45- final String[] projection = new String[] { Nodes._ID,
46- Nodes.NODE_RESOURCE_PATH, Nodes.NODE_GENERATION };
47+ final String[] projection = new String[] {
48+ Nodes._ID, Nodes.NODE_RESOURCE_PATH, Nodes.NODE_GENERATION,
49+ Nodes.NODE_DATA
50+ };
51 final String selection = Nodes.NODE_RESOURCE_PATH + "=?";
52
53 for (NodeInfo child : children) {
54@@ -686,6 +690,22 @@
55 values.put(Nodes.NODE_IS_CACHED, false);
56 values.put(Nodes.NODE_DATA, "");
57
58+ String data = c.getString(c.getColumnIndex(Nodes.NODE_DATA));
59+ try {
60+ if (!TextUtils.isEmpty(data)) {
61+ if (data.startsWith(ContentResolver.SCHEME_FILE)) {
62+ // Legacy check.
63+ data = data.substring(7); //"file://".length()
64+ }
65+ File cachedFile = new File(data);
66+ if (cachedFile.exists()) {
67+ cachedFile.delete();
68+ }
69+ }
70+ } catch (Exception e) {
71+ // This is simple cleanup, ignore.
72+ }
73+
74 Uri uri = MetaUtilities.buildNodeUri(id);
75 ContentProviderOperation op = ContentProviderOperation
76 .newUpdate(uri)
77
78=== modified file 'src/com/ubuntuone/android/files/util/TransferUtils.java'
79--- src/com/ubuntuone/android/files/util/TransferUtils.java 2012-04-27 18:03:18 +0000
80+++ src/com/ubuntuone/android/files/util/TransferUtils.java 2012-05-17 14:15:25 +0000
81@@ -7,6 +7,7 @@
82 import android.database.Cursor;
83 import android.net.Uri;
84
85+import com.ubuntuone.android.files.provider.MetaContract.Nodes;
86 import com.ubuntuone.android.files.provider.TransfersContract.Downloads;
87 import com.ubuntuone.android.files.provider.TransfersContract.TransferPriority;
88 import com.ubuntuone.android.files.provider.TransfersContract.TransferState;
89@@ -94,6 +95,13 @@
90 resolver.delete(uri, null, null);
91 }
92
93+ public static void dequeueByResourcePath(ContentResolver resolver, Uri uri,
94+ String resourcePath) {
95+ String where = Downloads.RESOURCE_PATH + "=?";
96+ String[] selectionArgs = new String[] { resourcePath };
97+ resolver.delete(uri, where, selectionArgs);
98+ }
99+
100 public static void dequeue(ContentResolver resolver, Uri uri, String state) {
101 String selection = Uploads.STATE + "=?";
102 String[] selectionArgs = new String[] { state };

Subscribers

People subscribed via source and target branches

to status/vote changes: