chiark / gitweb /
allow spaces in filenames
authorHans-Christoph Steiner <hans@eds.org>
Tue, 19 Sep 2017 08:57:29 +0000 (10:57 +0200)
committerHans-Christoph Steiner <hans@eds.org>
Tue, 19 Sep 2017 18:13:36 +0000 (20:13 +0200)
This fixes all the bugs I could find that prevented fdroid from
handling files with spaces in them.  This is more important now that
fdroid supports random media files, and Repomaker

fdroidserver/common.py
fdroidserver/update.py
tests/run-tests

index 807974d6013a9f942231c19f75d4d3522a44ec5c..c8442d5ebc453963197a2eddd8e86293a7bb75ab 100644 (file)
@@ -1599,6 +1599,13 @@ class KnownApks:
     """
 
     def __init__(self):
+        '''Load filename/date info about previously seen APKs
+
+        Since the appid and date strings both will never have spaces,
+        this is parsed as a list from the end to allow the filename to
+        have any combo of spaces.
+        '''
+
         self.path = os.path.join('stats', 'known_apks.txt')
         self.apks = {}
         if os.path.isfile(self.path):
@@ -1608,7 +1615,10 @@ class KnownApks:
                     if len(t) == 2:
                         self.apks[t[0]] = (t[1], None)
                     else:
-                        self.apks[t[0]] = (t[1], datetime.strptime(t[2], '%Y-%m-%d'))
+                        appid = t[-2]
+                        date = datetime.strptime(t[-1], '%Y-%m-%d')
+                        filename = line[0:line.rfind(appid) - 1]
+                        self.apks[filename] = (appid, date)
         self.changed = False
 
     def writeifchanged(self):
index 653792764674a50ba80fc765805eb87856841659..99fb80e5d7626631e2ccbc004ea66077f28a8df4 100644 (file)
@@ -1197,16 +1197,6 @@ def process_apk(apkcache, apkfilename, repodir, knownapks, use_date_from_apk=Fal
      apk is the scanned apk information, and cachechanged is True if the apkcache got changed.
     """
 
-    if ' ' in apkfilename:
-        if options.rename_apks:
-            newfilename = apkfilename.replace(' ', '_')
-            os.rename(os.path.join(repodir, apkfilename),
-                      os.path.join(repodir, newfilename))
-            apkfilename = newfilename
-        else:
-            logging.critical("Spaces in filenames are not allowed.")
-            return True, None, False
-
     apk = {}
     apkfile = os.path.join(repodir, apkfilename)
 
index 8558794e0145193de025233c53c8b81f2b01da96..e0986b97a892f09ddfec2bee7e9af6ec3fd58117 100755 (executable)
@@ -8,14 +8,14 @@ echo_header() {
 
 copy_apks_into_repo() {
     set +x
-    for f in `find $APKDIR -name '*.apk' | grep -F -v -e unaligned -e unsigned -e badsig -e badcert -e bad-unicode`; do
-        name=$(basename $(dirname `dirname $f`))
+    find $APKDIR -type f -name '*.apk' -print0 | while IFS= read -r -d '' f; do
+        echo $f | grep -F -v -e unaligned -e unsigned -e badsig -e badcert -e bad-unicode || continue
         apk=`$aapt dump badging "$f" | sed -n "s,^package: name='\(.*\)' versionCode='\([0-9][0-9]*\)' .*,\1_\2.apk,p"`
-        test $f -nt repo/$apk && rm -f repo/$apk  # delete existing if $f is newer
+        test "$f" -nt repo/$apk && rm -f repo/$apk  # delete existing if $f is newer
         if [ ! -e repo/$apk ] && [ ! -e archive/$apk ]; then
             echo "$f --> repo/$apk"
-            ln $f $1/repo/$apk || \
-                rsync -axv $f $1/repo/$apk # rsync if hard link is not possible
+            ln "$f" $1/repo/$apk || \
+                rsync -axv "$f" $1/repo/$apk # rsync if hard link is not possible
         fi
     done
     set -x