-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#!/usr/bin/env python3 | ||
import pyalpm | ||
import pycman | ||
import tarfile | ||
import sys, os, os.path | ||
|
||
pacmanconf = pycman.config.init_with_config("/etc/pacman.conf") | ||
rootdir = pacmanconf.rootdir | ||
|
||
def local_database(): | ||
handle = pacmanconf | ||
localdb = handle.get_localdb() | ||
packages = localdb.pkgcache | ||
syncdbs = handle.get_syncdbs() | ||
db = dict() | ||
for pkg in packages: | ||
for syncdb in syncdbs: | ||
if syncdb.get_pkg(pkg.name) is not None: | ||
db[pkg.name] = syncdb.get_pkg(pkg.name) | ||
return db | ||
|
||
def get_pkgfiles(package): | ||
db = local_database() | ||
pkg = db[package].filename | ||
result = [] | ||
for d in pacmanconf.cachedirs: | ||
p = os.path.join(d, pkg) | ||
if os.path.exists(p): | ||
result.append(p) | ||
return result | ||
|
||
def error_file(file, pkgfile, pkgname): | ||
print(f'"{{file}}" in {{pkgfile}} of {{pkgname}} mismatch') | ||
|
||
def check_pkgfile(pkgname, pkgfile): | ||
with tarfile.open(pkgfile) as tar: | ||
for fn in tar: | ||
fnpath = os.path.join(rootdir, fn.name) | ||
if fn.isdir(): | ||
if not os.path.isdir(fnpath): | ||
error_file(fnpath, pkgfile, pkgname) | ||
# else if fn.issym(): | ||
# if not os.path.issym(fnpath): | ||
|
||
def main(): | ||
for pkgname in sys.args: | ||
for pkgfile in get_pkgfiles(pkgname): | ||
check_pkgfile(pkgname, pkgfile) | ||
|
||
if __name__ == '__main__': | ||
main() |