From e9abbfa743b00f66131e6df4fafce6bc18fa51d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Fri, 3 Jan 2014 20:47:08 +0100 Subject: [PATCH] Add 'repo.version' integer --- src/org/fdroid/fdroid/DB.java | 49 ++++++++++++++--------- src/org/fdroid/fdroid/ManageRepo.java | 2 +- src/org/fdroid/fdroid/RepoXMLHandler.java | 37 +++++++++++++---- 3 files changed, 61 insertions(+), 27 deletions(-) diff --git a/src/org/fdroid/fdroid/DB.java b/src/org/fdroid/fdroid/DB.java index 40cbb8626..127b784ec 100644 --- a/src/org/fdroid/fdroid/DB.java +++ b/src/org/fdroid/fdroid/DB.java @@ -430,6 +430,7 @@ public class DB { public String address; public String name; public String description; + public int version; // index version, i.e. what fdroidserver built it - 0 if not specified public boolean inuse; public int priority; public String pubkey; // null for an unsigned repo @@ -438,7 +439,7 @@ public class DB { public String lastetag; // last etag we updated from, null forces update } - private final int DBVersion = 33; + private final int DBVersion = 34; private static void createAppApk(SQLiteDatabase db) { db.execSQL(CREATE_TABLE_APP); @@ -504,6 +505,7 @@ public class DB { mContext.getString(R.string.default_repo_name)); values.put("description", mContext.getString(R.string.default_repo_description)); + values.put("version", 0); String pubkey = mContext.getString(R.string.default_repo_pubkey); String fingerprint = DB.calcFingerprint(pubkey); values.put("pubkey", pubkey); @@ -521,9 +523,11 @@ public class DB { mContext.getString(R.string.default_repo_name2)); values.put("description", mContext.getString(R.string.default_repo_description2)); + values.put("version", 0); // default #2 is /archive which has the same key as /repo values.put("pubkey", pubkey); values.put("fingerprint", fingerprint); + values.put("maxage", 0); values.put("inuse", 0); values.put("priority", 20); values.put("lastetag", (String) null); @@ -611,6 +615,10 @@ public class DB { if (oldVersion < 30) { db.execSQL("alter table " + TABLE_REPO + " add column maxage integer not null default 0"); } + + if (oldVersion < 34) { + db.execSQL("alter table " + TABLE_REPO + " add column version integer not null default 0"); + } } } @@ -1283,8 +1291,8 @@ public class DB { Cursor c = null; try { c = db.query(TABLE_REPO, new String[] { "address", "name", - "description", "inuse", "priority", "pubkey", "fingerprint", - "maxage", "lastetag" }, + "description", "version", "inuse", "priority", "pubkey", + "fingerprint", "maxage", "lastetag" }, "id = ?", new String[] { Integer.toString(id) }, null, null, null); if (!c.moveToFirst()) return null; @@ -1293,12 +1301,13 @@ public class DB { repo.address = c.getString(0); repo.name = c.getString(1); repo.description = c.getString(2); - repo.inuse = (c.getInt(3) == 1); - repo.priority = c.getInt(4); - repo.pubkey = c.getString(5); - repo.fingerprint = c.getString(6); - repo.maxage = c.getInt(7); - repo.lastetag = c.getString(8); + repo.version = c.getInt(3); + repo.inuse = (c.getInt(4) == 1); + repo.priority = c.getInt(5); + repo.pubkey = c.getString(6); + repo.fingerprint = c.getString(7); + repo.maxage = c.getInt(8); + repo.lastetag = c.getString(9); return repo; } finally { if (c != null) @@ -1312,8 +1321,8 @@ public class DB { Cursor c = null; try { c = db.query(TABLE_REPO, new String[] { "id", "address", "name", - "description", "inuse", "priority", "pubkey", "fingerprint", - "maxage", "lastetag" }, + "description", "version", "inuse", "priority", "pubkey", + "fingerprint", "maxage", "lastetag" }, null, null, null, null, "priority"); c.moveToFirst(); while (!c.isAfterLast()) { @@ -1322,12 +1331,13 @@ public class DB { repo.address = c.getString(1); repo.name = c.getString(2); repo.description = c.getString(3); - repo.inuse = (c.getInt(4) == 1); - repo.priority = c.getInt(5); - repo.pubkey = c.getString(6); - repo.fingerprint = c.getString(7); - repo.maxage = c.getInt(8); - repo.lastetag = c.getString(9); + repo.version = c.getInt(4); + repo.inuse = (c.getInt(5) == 1); + repo.priority = c.getInt(6); + repo.pubkey = c.getString(7); + repo.fingerprint = c.getString(8); + repo.maxage = c.getInt(9); + repo.lastetag = c.getString(10); repos.add(repo); c.moveToNext(); } @@ -1357,6 +1367,7 @@ public class DB { ContentValues values = new ContentValues(); values.put("name", repo.name); values.put("description", repo.description); + values.put("version", repo.version); values.put("inuse", repo.inuse); values.put("priority", repo.priority); values.put("pubkey", repo.pubkey); @@ -1380,12 +1391,14 @@ public class DB { } public void addRepo(String address, String name, String description, - int priority, String pubkey, String fingerprint, int maxage, boolean inuse) + int version, int priority, String pubkey, String fingerprint, + int maxage, boolean inuse) throws SecurityException { ContentValues values = new ContentValues(); values.put("address", address); values.put("name", name); values.put("description", description); + values.put("version", version); values.put("inuse", inuse ? 1 : 0); values.put("priority", priority); values.put("pubkey", pubkey); diff --git a/src/org/fdroid/fdroid/ManageRepo.java b/src/org/fdroid/fdroid/ManageRepo.java index 6e4db92bd..bf6414ed8 100644 --- a/src/org/fdroid/fdroid/ManageRepo.java +++ b/src/org/fdroid/fdroid/ManageRepo.java @@ -218,7 +218,7 @@ public class ManageRepo extends ListActivity { protected void addRepo(String repoUri, String fingerprint) { try { DB db = DB.getDB(); - db.addRepo(repoUri, null, null, 10, null, fingerprint, 0, true); + db.addRepo(repoUri, null, null, 0, 10, null, fingerprint, 0, true); } finally { DB.releaseDB(); } diff --git a/src/org/fdroid/fdroid/RepoXMLHandler.java b/src/org/fdroid/fdroid/RepoXMLHandler.java index 5b0c91b38..f12d004ea 100644 --- a/src/org/fdroid/fdroid/RepoXMLHandler.java +++ b/src/org/fdroid/fdroid/RepoXMLHandler.java @@ -64,8 +64,9 @@ public class RepoXMLHandler extends DefaultHandler { private DB.Apk curapk = null; private StringBuilder curchars = new StringBuilder(); - // After processing the XML, this will be null if the index didn't specify - // a maximum age - otherwise it will be the value specified. + // After processing the XML, these will be null if the index didn't specify + // them - otherwise it will be the value specified. + private String version; private String maxage; // After processing the XML, this will be null if the index specified a @@ -262,10 +263,12 @@ public class RepoXMLHandler extends DefaultHandler { public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { super.startElement(uri, localName, qName, attributes); + if (localName.equals("repo")) { String pk = attributes.getValue("", "pubkey"); if (pk != null) pubkey = pk; + version = attributes.getValue("", "version"); maxage = attributes.getValue("", "maxage"); String nm = attributes.getValue("", "name"); if (nm != null) @@ -273,6 +276,7 @@ public class RepoXMLHandler extends DefaultHandler { String dc = attributes.getValue("", "description"); if (dc != null) description = dc; + } else if (localName.equals("application") && curapp == null) { curapp = new DB.App(); curapp.detail_Populated = true; @@ -283,11 +287,13 @@ public class RepoXMLHandler extends DefaultHandler { new ProgressListener.Event( RepoXMLHandler.PROGRESS_TYPE_PROCESS_XML, progressCounter, totalAppCount, progressData)); + } else if (localName.equals("package") && curapp != null && curapk == null) { curapk = new DB.Apk(); curapk.id = curapp.id; curapk.repo = repo.id; hashType = null; + } else if (localName.equals("hash") && curapk != null) { hashType = attributes.getValue("", "type"); } @@ -469,6 +475,17 @@ public class RepoXMLHandler extends DefaultHandler { DB.releaseDB(); } } + boolean updateRepo = false; + + if (handler.version != null) { + int version = Integer.parseInt(handler.version); + if (version != repo.version) { + Log.d("FDroid", "Repo specified a new version: from " + + repo.version + " to " + version); + repo.version = version; + updateRepo = true; + } + } if (handler.maxage != null) { int maxage = Integer.parseInt(handler.maxage); @@ -476,12 +493,16 @@ public class RepoXMLHandler extends DefaultHandler { Log.d("FDroid", "Repo specified a new maximum age - updated"); repo.maxage = maxage; - try { - DB db = DB.getDB(); - db.updateRepoByAddress(repo); - } finally { - DB.releaseDB(); - } + updateRepo = true; + } + } + + if (updateRepo) { + try { + DB db = DB.getDB(); + db.updateRepoByAddress(repo); + } finally { + DB.releaseDB(); } }