Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get_tested_package(name, testdir):
filename = Path(name).name + '-*.rpm'
pkg_path = list(get_tested_path(name).parent.glob(filename))[0]
return Pkg(pkg_path, testdir)
continue
for pkg in pkgs:
with pkg:
runChecks(pkg)
packages_checked += 1
for dname in dirs:
try:
for path, _, files in os.walk(dname):
for fname in files:
fname = os.path.abspath(os.path.join(path, fname))
try:
if fname.endswith('.rpm') or \
fname.endswith('.spm'):
with Pkg.Pkg(fname, extract_dir) as pkg:
runChecks(pkg)
packages_checked += 1
elif fname.endswith('.spec'):
with Pkg.FakePkg(fname) as pkg:
runSpecChecks(pkg, fname)
specfiles_checked += 1
except KeyboardInterrupt:
print_warning(
'(none): E: interrupted while reading %s' %
fname)
sys.exit(2)
except Exception as e:
print_warning(
'(none): E: while reading %s: %s' % (fname, e))
pkgs = []
ts = rpm.TransactionSet()
if re.search(r'[?*]|\[.+\]', name):
mi = ts.dbMatch()
mi.pattern('name', rpm.RPMMIRE_GLOB, name)
else:
mi = ts.dbMatch('name', name)
for hdr in mi:
pkgs.append(InstalledPkg(name, hdr))
return pkgs
# Class to provide an API to an installed package
class InstalledPkg(Pkg):
def __init__(self, name, hdr=None):
if not hdr:
ts = rpm.TransactionSet()
mi = ts.dbMatch('name', name)
if not mi:
raise KeyError(name)
try:
hdr = next(mi)
except StopIteration:
raise KeyError(name)
super().__init__(name, '/', hdr, extracted=True)
# create a fake filename to satisfy some checks on the filename
self.filename = '%s-%s-%s.%s.rpm' % \
(self.name, self[rpm.RPMTAG_VERSION], self[rpm.RPMTAG_RELEASE],
self[rpm.RPMTAG_ARCH])
def validate_file(self, pname):
try:
if pname.suffix == '.rpm' or pname.suffix == '.spm':
with Pkg(pname, self.config.configuration['ExtractDir']) as pkg:
self.run_checks(pkg)
elif pname.suffix == '.spec':
with FakePkg(pname) as pkg:
self.run_spec_checks(pkg)
except Exception as e:
print_warning(f'(none): E: while reading {pname}: {e}')
def __load_pkg(self, name):
# FIXME: redo to try file/installed and proceed based on that, or pick
# one of the selected first
tmpdir = tempfile.gettempdir()
try:
if name.is_file():
return Pkg(name, tmpdir)
except TypeError:
pass
inst = getInstalledPkgs(name)
if not inst:
raise KeyError(f'No installed packages by name {name}')
if len(inst) > 1:
raise KeyError(f'More than one installed packages by name {name}')
return inst[0]
pkgfile.magic = "symbolic link to `%s'" % pkgfile.linkto
elif not pkgfile.size:
pkgfile.magic = 'empty'
if (not pkgfile.magic and
not pkgfile.is_ghost and _magic):
# file() method evaluates every file twice with python2,
# use descriptor() method instead
try:
fd = os.open(pkgfile.path, os.O_RDONLY)
pkgfile.magic = byte_to_string(_magic.descriptor(fd))
os.close(fd)
except OSError:
pass
if pkgfile.magic is None:
pkgfile.magic = ''
elif Pkg._magic_from_compressed_re.search(pkgfile.magic):
# Discard magic from inside compressed files ('file -z')
# until PkgFile gets decompression support. We may get
# such magic strings from package headers already now;
# for example Fedora's rpmbuild as of F-11's 4.7.1 is
# patched so it generates them.
pkgfile.magic = ''
if filecaps:
pkgfile.filecaps = filecaps[idx]
ret[pkgfile.name] = pkgfile
return ret