mirror of
https://gitlab.com/fdroid/fdroidserver.git
synced 2024-11-14 02:50:12 +01:00
update: use KnownApks dates to check system clock on offline machines
KnownApks provides a reliable source of a relatively recent date.
This commit is contained in:
parent
1219f07d3b
commit
d46d9574b4
@ -40,7 +40,7 @@ import json
|
||||
import xml.etree.ElementTree as XMLElementTree
|
||||
|
||||
from binascii import hexlify
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timedelta
|
||||
from distutils.version import LooseVersion
|
||||
from queue import Queue
|
||||
from zipfile import ZipFile
|
||||
@ -1716,6 +1716,23 @@ def natural_key(s):
|
||||
return [int(sp) if sp.isdigit() else sp for sp in re.split(r'(\d+)', s)]
|
||||
|
||||
|
||||
def check_system_clock(dt_obj, path):
|
||||
"""Check if system clock is updated based on provided date
|
||||
|
||||
If an APK has files newer than the system time, suggest updating
|
||||
the system clock. This is useful for offline systems, used for
|
||||
signing, which do not have another source of clock sync info. It
|
||||
has to be more than 24 hours newer because ZIP/APK files do not
|
||||
store timezone info
|
||||
|
||||
"""
|
||||
checkdt = dt_obj - timedelta(1)
|
||||
if datetime.today() < checkdt:
|
||||
logging.warning(_('System clock is older than date in {path}!').format(path=path)
|
||||
+ '\n' + _('Set clock to that time using:') + '\n'
|
||||
+ 'sudo date -s "' + str(dt_obj) + '"')
|
||||
|
||||
|
||||
class KnownApks:
|
||||
"""permanent store of existing APKs with the date they were added
|
||||
|
||||
@ -1744,6 +1761,7 @@ class KnownApks:
|
||||
date = datetime.strptime(t[-1], '%Y-%m-%d')
|
||||
filename = line[0:line.rfind(appid) - 1]
|
||||
self.apks[filename] = (appid, date)
|
||||
check_system_clock(date, self.path)
|
||||
self.changed = False
|
||||
|
||||
def writeifchanged(self):
|
||||
|
@ -29,7 +29,7 @@ import zipfile
|
||||
import hashlib
|
||||
import pickle
|
||||
import time
|
||||
from datetime import datetime, timedelta
|
||||
from datetime import datetime
|
||||
from argparse import ArgumentParser
|
||||
|
||||
import collections
|
||||
@ -1297,22 +1297,11 @@ def process_apk(apkcache, apkfilename, repodir, knownapks, use_date_from_apk=Fal
|
||||
|
||||
apkzip = zipfile.ZipFile(apkfile, 'r')
|
||||
|
||||
# if an APK has files newer than the system time, suggest updating
|
||||
# the system clock. This is useful for offline systems, used for
|
||||
# signing, which do not have another source of clock sync info. It
|
||||
# has to be more than 24 hours newer because ZIP/APK files do not
|
||||
# store timezone info
|
||||
manifest = apkzip.getinfo('AndroidManifest.xml')
|
||||
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.warning('System clock is older than manifest in: '
|
||||
+ apkfilename
|
||||
+ '\nSet clock to that time using:\n'
|
||||
+ 'sudo date -s "' + str(dt_obj) + '"')
|
||||
common.check_system_clock(datetime(*manifest.date_time), apkfilename)
|
||||
|
||||
# extract icons from APK zip file
|
||||
iconfilename = "%s.%s.png" % (apk['packageName'], apk['versionCode'])
|
||||
|
Loading…
Reference in New Issue
Block a user