Implement challenge for APKINDEX.tar.gz (part of #64)
This commit is contained in:
parent
ce147b0381
commit
748bd43620
|
@ -16,9 +16,45 @@ GNU General Public License for more details.
|
|||
You should have received a copy of the GNU General Public License
|
||||
along with pmbootstrap. If not, see <http://www.gnu.org/licenses/>.
|
||||
"""
|
||||
import os
|
||||
import glob
|
||||
import pmb.parse.apkindex
|
||||
|
||||
|
||||
def apkindex(args, apkindex_path):
|
||||
raise NotImplementedError("Challenge for APKINDEX.tar.gz is not"
|
||||
" implemented yet (see issue #64 for more"
|
||||
" information).")
|
||||
def apkindex(args, path_apkindex, apk_suffix=""):
|
||||
"""
|
||||
Verify an APKINDEX.tar.gz file, and its repository folder:
|
||||
- Each apk must be defined inside the APKINDEX (once!)
|
||||
- There must be no extra files
|
||||
|
||||
:param path_apkindex: full path to the APKINDEX.tar.gz
|
||||
:param apk_suffix: set this to ".unverified", if all apk files in
|
||||
the repository have such a suffix appended.
|
||||
"""
|
||||
# Parse the apkindex file
|
||||
content = pmb.parse.apkindex.parse(args, path_apkindex, True)
|
||||
folder = os.path.dirname(path_apkindex)
|
||||
|
||||
# All listed packages must exist
|
||||
found = []
|
||||
for pkgname_alias, block in content.items():
|
||||
apk = (block["pkgname"] + "-" + block["version"] + ".apk" +
|
||||
apk_suffix)
|
||||
buildinfo = (block["pkgname"] + "-" + block["version"] +
|
||||
".apk.buildinfo.json")
|
||||
if not os.path.exists(folder + "/" + apk):
|
||||
raise RuntimeError("Could not find file '" + apk +
|
||||
"' mentioned in " + path_apkindex)
|
||||
# Mark the apk and its buildinfo (if it exists) as found
|
||||
if apk not in found:
|
||||
found.append(apk)
|
||||
if os.path.exists(folder + "/" + buildinfo):
|
||||
found.append(buildinfo)
|
||||
|
||||
# There must be no extra files
|
||||
for path in glob.glob(folder + "/*"):
|
||||
name = os.path.basename(path)
|
||||
if name == "APKINDEX.tar.gz" or name in found:
|
||||
continue
|
||||
raise RuntimeError("Unexpected file '" + name + "' inside the"
|
||||
" repository folder: " + folder)
|
||||
|
|
Loading…
Reference in New Issue