A couple of fixes to the repo update process

This commit is contained in:
Ciaran Gultnieks 2010-10-20 17:29:26 +01:00
parent 861d094e9d
commit 2c39dae035
4 changed files with 23 additions and 18 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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));

View File

@ -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