chiark / gitweb /
Merge branch 'p2' into 'master'
authorDaniel Martí <mvdan@mvdan.cc>
Thu, 18 Feb 2016 13:35:33 +0000 (13:35 +0000)
committerDaniel Martí <mvdan@mvdan.cc>
Thu, 18 Feb 2016 13:35:33 +0000 (13:35 +0000)
Fix update crash in case of unset dates in APK; add an option to use APK's entry date

I encountered an error when I tried to add [TrackID APK](https://play.google.com/store/apps/details?id=com.sonyericsson.trackid) (files in the APK don't have dates set): as far as I can remember `datetime(*manifest.date_time)` was raising `ValueError`.

Also add an option to use date from APK as this APK's entry date (may be useful in case of a simple binary repo): `fdroid update --use-date-from-apk`.

I should have split this commit, but I hope this would be OK too.

See merge request !104

completion/bash-completion
fdroidserver/update.py

index f0ce84a355305a84b1a83c7f1b6b889cd4d7deed..f2632d676baf797e55bd082f87a54d5667a00b86 100644 (file)
@@ -136,7 +136,7 @@ __complete_update() {
        opts="-c -v -q -b -i -I -e -w"
        lopts="--create-metadata --verbose --quiet --buildreport
  --interactive --icons --editor --wiki --pretty --clean --delete-unknown
- --nosign"
+ --nosign --use-date-from-apk"
        case "${prev}" in
                -e|--editor)
                        _filedir
index aa9a9a3b12cf340366757c8d9ee528edaec84801..67de608daab9fbc9e07aa826b6490faff8195f38 100644 (file)
@@ -405,7 +405,7 @@ def getsig(apkpath):
     return md5(cert_encoded.encode('hex')).hexdigest()
 
 
-def scan_apks(apps, apkcache, repodir, knownapks):
+def scan_apks(apps, apkcache, repodir, knownapks, use_date_from_apk=False):
     """Scan the apks in the given repo directory.
 
     This also extracts the icons.
@@ -414,6 +414,8 @@ def scan_apks(apps, apkcache, repodir, knownapks):
     :param apkcache: current apk cache information
     :param repodir: repo directory to scan
     :param knownapks: known apks info
+    :param use_date_from_apk: use date from APK (instead of current date)
+                              for newly added APKs
     :returns: (apks, cachechanged) where apks is a list of apk information,
               and cachechanged is True if the apkcache got changed.
     """
@@ -568,12 +570,16 @@ def scan_apks(apps, apkcache, repodir, knownapks):
             # has to be more than 24 hours newer because ZIP/APK files do not
             # store timezone info
             manifest = apkzip.getinfo('AndroidManifest.xml')
-            dt_obj = datetime(*manifest.date_time)
-            checkdt = dt_obj - timedelta(1)
-            if datetime.today() < checkdt:
-                logging.warn('System clock is older than manifest in: '
-                             + apkfilename + '\nSet clock to that time using:\n'
-                             + 'sudo date -s "' + str(dt_obj) + '"')
+            if manifest.date_time[1] == 0:  # month can't be zero
+                logging.debug('AndroidManifest.xml has no date')
+            else:
+                dt_obj = datetime(*manifest.date_time)
+                checkdt = dt_obj - timedelta(1)
+                if datetime.today() < checkdt:
+                    logging.warn('System clock is older than manifest in: '
+                                 + apkfilename
+                                 + '\nSet clock to that time using:\n'
+                                 + 'sudo date -s "' + str(dt_obj) + '"')
 
             iconfilename = "%s.%s.png" % (
                 apk['id'],
@@ -685,6 +691,10 @@ def scan_apks(apps, apkcache, repodir, knownapks):
             # Record in known apks, getting the added date at the same time..
             added = knownapks.recordapk(apk['apkname'], apk['id'])
             if added:
+                if use_date_from_apk and manifest.date_time[1] != 0:
+                    added = datetime(*manifest.date_time).timetuple()
+                    logging.debug("Using date from APK")
+
                 apk['added'] = added
 
             apkcache[apkfilename] = apk
@@ -1130,6 +1140,8 @@ def main():
                         help="Clean update - don't uses caches, reprocess all apks")
     parser.add_argument("--nosign", action="store_true", default=False,
                         help="When configured for signed indexes, create only unsigned indexes at this stage")
+    parser.add_argument("--use-date-from-apk", action="store_true", default=False,
+                        help="Use date from apk instead of current time for newly added apks")
     options = parser.parse_args()
 
     config = common.read_config(options)
@@ -1204,7 +1216,7 @@ def main():
     delete_disabled_builds(apps, apkcache, repodirs)
 
     # Scan all apks in the main repo
-    apks, cachechanged = scan_apks(apps, apkcache, repodirs[0], knownapks)
+    apks, cachechanged = scan_apks(apps, apkcache, repodirs[0], knownapks, options.use_date_from_apk)
 
     # Generate warnings for apk's with no metadata (or create skeleton
     # metadata files, if requested on the command line)
@@ -1246,7 +1258,7 @@ def main():
 
     # Scan the archive repo for apks as well
     if len(repodirs) > 1:
-        archapks, cc = scan_apks(apps, apkcache, repodirs[1], knownapks)
+        archapks, cc = scan_apks(apps, apkcache, repodirs[1], knownapks, options.use_date_from_apk)
         if cc:
             cachechanged = True
     else: