Normalize Repo.lastUpdated values to contain the date and time
This also converts old Repo.lastUpdated values rather than just failing. index.xml handling used to store the Repo "Last Updated" date used to store the value as just an ISO date (2019-04-29), then the time was added. So if date/time parsing fails, this falls back to trying to parse just the date. null is returned when parsing fails, and the Latest Tab shows nothing if the Last Updated is null. Some related tests were also tweaked. Hopefully: closes fdroid/fdroidclient#1757
This commit is contained in:
parent
d62c0cf723
commit
c0c5721f6a
@ -414,7 +414,7 @@ public class IndexUpdater {
|
||||
|
||||
Utils.debugLog(TAG, "Saving new signing certificate in the database for " + repo.address);
|
||||
ContentValues values = new ContentValues(2);
|
||||
values.put(RepoTable.Cols.LAST_UPDATED, Utils.formatDate(new Date(), ""));
|
||||
values.put(RepoTable.Cols.LAST_UPDATED, Utils.formatTime(new Date(), ""));
|
||||
values.put(RepoTable.Cols.SIGNING_CERT, Hasher.hex(rawCertFromJar));
|
||||
RepoProvider.Helper.update(context, repo, values);
|
||||
}
|
||||
|
@ -470,7 +470,7 @@ public class IndexV1Updater extends IndexUpdater {
|
||||
}
|
||||
Utils.debugLog(TAG, "Saving new signing certificate to database for " + repo.address);
|
||||
ContentValues values = new ContentValues(2);
|
||||
values.put(Schema.RepoTable.Cols.LAST_UPDATED, Utils.formatDate(new Date(), ""));
|
||||
values.put(Schema.RepoTable.Cols.LAST_UPDATED, Utils.formatTime(new Date(), ""));
|
||||
values.put(Schema.RepoTable.Cols.SIGNING_CERT, Hasher.hex(rawCertFromJar));
|
||||
RepoProvider.Helper.update(context, repo, values);
|
||||
repo.signingCertificate = certFromJar;
|
||||
|
@ -165,7 +165,8 @@ public class Repo extends ValueObject {
|
||||
inuse = cursor.getInt(i) == 1;
|
||||
break;
|
||||
case Cols.LAST_UPDATED:
|
||||
lastUpdated = Utils.parseTime(cursor.getString(i), null);
|
||||
String dateString = cursor.getString(i);
|
||||
lastUpdated = Utils.parseTime(dateString, Utils.parseDate(dateString, null));
|
||||
break;
|
||||
case Cols.MAX_AGE:
|
||||
maxage = cursor.getInt(i);
|
||||
@ -296,7 +297,7 @@ public class Repo extends ValueObject {
|
||||
|
||||
if (values.containsKey(Cols.LAST_UPDATED)) {
|
||||
final String dateString = values.getAsString(Cols.LAST_UPDATED);
|
||||
lastUpdated = Utils.parseTime(dateString, null);
|
||||
lastUpdated = Utils.parseTime(dateString, Utils.parseDate(dateString, null));
|
||||
}
|
||||
|
||||
if (values.containsKey(Cols.MAX_AGE)) {
|
||||
|
@ -11,7 +11,6 @@ import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import org.fdroid.fdroid.AppUpdateStatusManager;
|
||||
import org.fdroid.fdroid.Utils;
|
||||
import org.fdroid.fdroid.data.Schema.RepoTable;
|
||||
@ -278,7 +277,8 @@ public class RepoProvider extends FDroidProvider {
|
||||
if (cursor != null) {
|
||||
if (cursor.getCount() > 0) {
|
||||
cursor.moveToFirst();
|
||||
lastUpdate = Utils.parseDate(cursor.getString(0), null);
|
||||
String dateString = cursor.getString(0);
|
||||
lastUpdate = Utils.parseTime(dateString, Utils.parseDate(dateString, null));
|
||||
}
|
||||
cursor.close();
|
||||
}
|
||||
|
@ -95,7 +95,7 @@ public class RepoProviderTest extends FDroidProviderTest {
|
||||
|
||||
private Repo setLastUpdate(Repo repo, Date date) {
|
||||
ContentValues values = new ContentValues(1);
|
||||
values.put(RepoTable.Cols.LAST_UPDATED, Utils.formatDate(date, null));
|
||||
values.put(RepoTable.Cols.LAST_UPDATED, Utils.formatTime(date, null));
|
||||
RepoProvider.Helper.update(context, repo, values);
|
||||
return RepoProvider.Helper.findByAddress(context, repo.address);
|
||||
}
|
||||
|
@ -897,6 +897,10 @@ public class RepoXMLHandlerTest {
|
||||
List<App> apps = actualDetails.apps;
|
||||
assertNotNull(apps);
|
||||
assertEquals(apps.size(), appCount);
|
||||
for (App app: apps) {
|
||||
assertTrue("Added should have been set", app.added.getTime() > 0);
|
||||
assertTrue("Last Updated should have been set", app.lastUpdated.getTime() > 0);
|
||||
}
|
||||
|
||||
List<Apk> apks = actualDetails.apks;
|
||||
assertNotNull(apks);
|
||||
|
Loading…
x
Reference in New Issue
Block a user