Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# Short-circuit stdin spec file check
stdin = sys.stdin.readlines()
if not stdin:
continue
with Pkg.FakePkg(arg) as pkg:
runSpecChecks(pkg, None, spec_lines=stdin)
specfiles_checked += 1
continue
try:
st = os.stat(arg)
isfile = True
if stat.S_ISREG(st[stat.ST_MODE]):
if arg.endswith('.spec'):
# Short-circuit spec file checks
with Pkg.FakePkg(arg) as pkg:
runSpecChecks(pkg, arg)
specfiles_checked += 1
elif '/' in arg or arg.endswith('.rpm') or \
arg.endswith('.spm'):
pkgs.append(Pkg.Pkg(arg, extract_dir))
else:
raise OSError
elif stat.S_ISDIR(st[stat.ST_MODE]):
dirs.append(arg)
continue
else:
raise OSError
except OSError:
ipkgs = Pkg.getInstalledPkgs(arg)
if not ipkgs:
def check_spec(self, pkg):
"""SCL spec file checks"""
spec = '\n'.join(Pkg.readlines(pkg.name))
if global_scl_definition.search(spec):
self.check_metapackage(pkg, spec)
elif scl_package_definition.search(spec):
self.check_scl_spec(pkg, spec)
elif scl_use.search(spec):
self.output.add_info('E', pkg, 'undeclared-scl')
def _check_non_utf8_spec_file(self, pkg):
"""Check if spec file has UTF-8 character encoding."""
if self._spec_file:
if not Pkg.is_utf8(self._spec_file):
self.output.add_info('E', pkg, 'non-utf8-spec-file',
self._spec_name or self._spec_file)
epoch = pkg[rpm.RPMTAG_EPOCH]
if epoch is None:
if self.use_epoch:
self.output.add_info('E', pkg, 'no-epoch-tag')
else:
if epoch > 99:
self.output.add_info('W', pkg, 'unreasonable-epoch', epoch)
epoch = str(epoch)
if self.use_epoch:
for tag in ('obsoletes', 'conflicts', 'provides', 'recommends',
'suggests', 'enhances', 'supplements'):
for x in (x for x in getattr(pkg, tag)()
if x[1] and x[2][0] is None):
self.output.add_info('W', pkg, 'no-epoch-in-%s' % tag,
Pkg.formatRequire(*x))
name = pkg.name
deps = pkg.requires + pkg.prereq
devel_depend = False
is_devel = FilesCheck.devel_regex.search(name)
is_source = pkg.is_source
for d in deps:
value = Pkg.formatRequire(*d)
if self.use_epoch and d[1] and d[2][0] is None and \
not d[0].startswith('rpmlib('):
self.output.add_info('W', pkg, 'no-epoch-in-dependency', value)
for r in self.invalid_requires:
if r.search(d[0]):
self.output.add_info('E', pkg, 'invalid-dependency', d[0])
if d[0].startswith('/usr/local/'):
specfiles_checked = 0
try:
# Loop over all file names given in arguments
dirs = []
for arg in args:
pkgs = []
isfile = False
try:
if arg == '-':
arg = '(standard input)'
# Short-circuit stdin spec file check
stdin = sys.stdin.readlines()
if not stdin:
continue
with Pkg.FakePkg(arg) as pkg:
runSpecChecks(pkg, None, spec_lines=stdin)
specfiles_checked += 1
continue
try:
st = os.stat(arg)
isfile = True
if stat.S_ISREG(st[stat.ST_MODE]):
if arg.endswith('.spec'):
# Short-circuit spec file checks
with Pkg.FakePkg(arg) as pkg:
runSpecChecks(pkg, arg)
specfiles_checked += 1
elif '/' in arg or arg.endswith('.rpm') or \
arg.endswith('.spm'):
pkgs.append(Pkg.Pkg(arg, extract_dir))
def check_source(self, pkg):
# lookup spec file
for fname, pkgfile in pkg.files().items():
if fname.endswith('.spec'):
self._spec_file = pkgfile.path
with Pkg.FakePkg(pkgfile.path) as package:
self.check_spec(package)
('Supplements', pkg.supplements),
('Suggests', pkg.suggests),
('Enhances', pkg.enhances),
('Recommends', pkg.recommends)):
for p in items:
e = Pkg.has_forbidden_controlchars(p)
if e:
self.output.add_info('E',
pkg,
'forbidden-controlchar-found',
'%s: %s' % (tagname, e))
value = Pkg.formatRequire(*p)
self._unexpanded_macros(pkg, '%s %s' % (tagname, value), value)
for p in (pkg.requires):
e = Pkg.has_forbidden_controlchars(p)
if e:
self.output.add_info('E',
pkg,
'forbidden-controlchar-found',
'Requires: %s' % e)
obss = pkg.obsoletes
if obss:
provs = pkg.provides
for prov in provs:
for obs in obss:
if Pkg.rangeCompare(obs, prov):
self.output.add_info('W', pkg, 'self-obsoletion',
'%s obsoletes %s' %
(Pkg.formatRequire(*obs),
Pkg.formatRequire(*prov)))
runSpecChecks(pkg, None, spec_lines=stdin)
specfiles_checked += 1
continue
try:
st = os.stat(arg)
isfile = True
if stat.S_ISREG(st[stat.ST_MODE]):
if arg.endswith('.spec'):
# Short-circuit spec file checks
with Pkg.FakePkg(arg) as pkg:
runSpecChecks(pkg, arg)
specfiles_checked += 1
elif '/' in arg or arg.endswith('.rpm') or \
arg.endswith('.spm'):
pkgs.append(Pkg.Pkg(arg, extract_dir))
else:
raise OSError
elif stat.S_ISDIR(st[stat.ST_MODE]):
dirs.append(arg)
continue
else:
raise OSError
except OSError:
ipkgs = Pkg.getInstalledPkgs(arg)
if not ipkgs:
print_warning(
'(none): E: no installed packages by name %s' % arg)
else:
ipkgs.sort(key=lambda x: locale.strxfrm(
x.header.sprintf('%{NAME}.%{ARCH}')))