From 2c39dae0354b8265ca38170ef4b7465b4f6e342e Mon Sep 17 00:00:00 2001 From: Ciaran Gultnieks Date: Wed, 20 Oct 2010 17:29:26 +0100 Subject: [PATCH] A couple of fixes to the repo update process --- src/org/fdroid/fdroid/AppDetails.java | 2 +- src/org/fdroid/fdroid/DB.java | 23 ++++++++++++++++++----- src/org/fdroid/fdroid/FDroid.java | 2 +- src/org/fdroid/fdroid/RepoXMLHandler.java | 14 +++----------- 4 files changed, 23 insertions(+), 18 deletions(-) diff --git a/src/org/fdroid/fdroid/AppDetails.java b/src/org/fdroid/fdroid/AppDetails.java index a3357525e..9fdb2daf1 100644 --- a/src/org/fdroid/fdroid/AppDetails.java +++ b/src/org/fdroid/fdroid/AppDetails.java @@ -271,7 +271,7 @@ public class AppDetails extends ListActivity { download_handler.sendMessage(msg); BufferedInputStream getit = new BufferedInputStream(new URL( - remotefile).openStream()); + remotefile).openStream(), 8192); FileOutputStream saveit = new FileOutputStream(localfile); BufferedOutputStream bout = new BufferedOutputStream(saveit, 1024); diff --git a/src/org/fdroid/fdroid/DB.java b/src/org/fdroid/fdroid/DB.java index 6b84f07ed..31f2f70f1 100644 --- a/src/org/fdroid/fdroid/DB.java +++ b/src/org/fdroid/fdroid/DB.java @@ -133,10 +133,10 @@ public class DB { Cursor c = db.rawQuery( "SELECT name FROM sqlite_master WHERE type='table' AND name= '" + TABLE_REPO + "'", null); - if (c.getCount() == 0) { - reset(); - } + boolean newinst = (c.getCount() == 0); c.close(); + if(newinst) + reset(); mPm = ctx.getPackageManager(); } @@ -209,6 +209,7 @@ public class DB { app.apks.add(apk); c2.moveToNext(); } + c2.close(); result.add(app); c.moveToNext(); @@ -262,6 +263,10 @@ public class DB { // Called before a repo update starts. public void beginUpdate() { + // Get a list of all apps. All the apps and apks in this list will + // have 'updated' set to false at this point, and we will only set + // it to true when we see the app/apk in a repository. Thus, at the + // end, any that are still false can be removed. updateApps = getApps(null, null, true); Log.d("FDroid", "AppUpdate: " + updateApps.size() + " apps before starting."); @@ -275,14 +280,20 @@ public class DB { if (!app.updated) { // The application hasn't been updated, so it's no longer // in the repos. + Log.d("FDroid", "AppUpdate: " + app.name + + " is no longer in any repository - removing"); db.delete(TABLE_APP, "id = '" + app.id + "'", null); + db.delete(TABLE_APK, "id = '" + app.id + "'", null); } else { for (Apk apk : app.apks) { if (!apk.updated) { // The package hasn't been updated, so this is a // version that's no longer available. + Log.d("FDroid", "AppUpdate: Package " + apk.id + "/" + + apk.version + + " is no longer in any repository - removing"); db.delete(TABLE_APK, "id = '" + app.id - + " and version ='" + apk.version + "'", null); + + "' and version ='" + apk.version + "'", null); } } } @@ -328,6 +339,7 @@ public class DB { app.hasUpdates = true; } } + break; } } if (!found) { @@ -338,6 +350,7 @@ public class DB { updateAppIfDifferent(null, upapp); for (Apk upapk : upapp.apks) { updateApkIfDifferent(null, upapk); + upapk.updated = true; } upapp.updated = true; updateApps.add(upapp); @@ -406,7 +419,7 @@ public class DB { c = db.rawQuery("select address, inuse, priority from " + TABLE_REPO + " order by priority", null); c.moveToFirst(); - while(!c.isAfterLast()) { + while (!c.isAfterLast()) { Repo repo = new Repo(); repo.address = c.getString(0); repo.inuse = (c.getInt(1) == 1); diff --git a/src/org/fdroid/fdroid/FDroid.java b/src/org/fdroid/fdroid/FDroid.java index 2281d90e1..d61ab3377 100644 --- a/src/org/fdroid/fdroid/FDroid.java +++ b/src/org/fdroid/fdroid/FDroid.java @@ -434,7 +434,7 @@ public class FDroid extends TabActivity implements OnItemClickListener { try { SAXParser sp = spf.newSAXParser(); XMLReader xr = sp.getXMLReader(); - RepoXMLHandler handler = new RepoXMLHandler(this, srv); + RepoXMLHandler handler = new RepoXMLHandler(this, srv, db); xr.setContentHandler(handler); InputStreamReader isr = new FileReader(new File(XML_PATH)); diff --git a/src/org/fdroid/fdroid/RepoXMLHandler.java b/src/org/fdroid/fdroid/RepoXMLHandler.java index ba7729d4d..8c527d884 100644 --- a/src/org/fdroid/fdroid/RepoXMLHandler.java +++ b/src/org/fdroid/fdroid/RepoXMLHandler.java @@ -39,24 +39,16 @@ public class RepoXMLHandler extends DefaultHandler { Context mctx; String mserver; - private DB db = null; + private DB db; private DB.App curapp = null; private DB.Apk curapk = null; private String curel = null; - public RepoXMLHandler(Context ctx, String srv) { + public RepoXMLHandler(Context ctx, String srv,DB db) { mctx = ctx; mserver = srv; - db = new DB(mctx); - db.beginUpdate(); - } - - @Override - public void endDocument() throws SAXException { - super.endDocument(); - db.endUpdate(); - db.close(); + this.db = db; } @Override