chiark / gitweb /
reuse os.stat() result when checking for non-APK files
authorHans-Christoph Steiner <hans@eds.org>
Wed, 2 Nov 2016 14:50:34 +0000 (15:50 +0100)
committerHans-Christoph Steiner <hans@eds.org>
Wed, 2 Nov 2016 17:10:13 +0000 (18:10 +0100)
This should make things a bit more efficient when running on lots of files,
unless python was already caching the result...

fdroidserver/update.py

index befad784f3cc56b98188fcde5f89ca5845ebbca8..30390f825d1652663e5bb614901cfb0143205c6d 100644 (file)
@@ -517,15 +517,16 @@ def scan_repo_files(apkcache, repodir, knownapks, use_date_from_file=False):
     cachechanged = False
     repo_files = []
     for name in os.listdir(repodir):
-        filename = os.path.join(repodir, name)
-        file_extension = common.get_file_extension(name)
         if name in ['index.jar', 'index.xml', 'index.html', 'categories.txt', ]:
             continue
+        file_extension = common.get_file_extension(name)
         if file_extension == 'apk' or file_extension == 'obb':
             continue
+        filename = os.path.join(repodir, name)
         if not os.path.isfile(filename):
             continue
-        if os.stat(filename).st_size == 0:
+        stat = os.stat(filename)
+        if stat.st_size == 0:
             logging.error(filename + ' is zero size!')
             sys.exit(1)
 
@@ -552,13 +553,13 @@ def scan_repo_files(apkcache, repodir, knownapks, use_date_from_file=False):
             srcfilename = name + ".src.tar.gz"
             if os.path.exists(os.path.join(repodir, srcfilename)):
                 repo_file['srcname'] = srcfilename
-            repo_file['size'] = os.path.getsize(filename)
+            repo_file['size'] = stat.st_size
 
             apkcache[name] = repo_file
             cachechanged = True
 
         if use_date_from_file:
-            timestamp = os.stat(filename).st_ctime
+            timestamp = stat.st_ctime
             default_date_param = datetime.fromtimestamp(timestamp).utctimetuple()
         else:
             default_date_param = None