Throw error messages in the functions
Throw error and warning messages in the particular methods, not in the check_binary method. Now it's in compliance with the rest of the checks. Add docstrings and use better names for variables (we don't want to have one-letter names).
This commit is contained in:
parent
7cc5563ead
commit
0142282db8
|
@ -6,6 +6,12 @@ from rpmlint.checks.AbstractCheck import AbstractCheck
|
|||
class FHSCheck(AbstractCheck):
|
||||
"""
|
||||
Validate that binary files are packaged according to FHS.
|
||||
|
||||
We follow FHS 3.0 specification that can be found at
|
||||
http://refspecs.linuxfoundation.org/FHS_3.0/fhs-3.0.pdf
|
||||
|
||||
usr_subdir lists allowed directories in /usr (FHS chapter 4.2 and 4.3)
|
||||
var_subdir lists allowed directories in /var (FHS chapter 5.2 and 5.3)
|
||||
"""
|
||||
usr_regex = re.compile('^/usr/([^/]+)')
|
||||
usr_subdir = ('X11R6', 'bin', 'games', 'include', 'lib', 'lib64',
|
||||
|
@ -24,49 +30,59 @@ class FHSCheck(AbstractCheck):
|
|||
usr_list = []
|
||||
|
||||
for fname in pkg.files:
|
||||
s = FHSCheck.usr_regex.search(fname)
|
||||
if s:
|
||||
d = s.group(1)
|
||||
if not self._check_usr_std_dir(d, usr_list):
|
||||
self.output.add_info('W', pkg, 'non-standard-dir-in-usr', d)
|
||||
else:
|
||||
s = FHSCheck.var_regex.search(fname)
|
||||
if s:
|
||||
d = s.group(1)
|
||||
if not self._check_var_FSSTND_dir(d, var_list):
|
||||
self.output.add_info('W', pkg, 'FSSTND-dir-in-var', d)
|
||||
elif not self._check_var_std_dir(s, var_list):
|
||||
self.output.add_info('W', pkg, 'non-standard-dir-in-var', d)
|
||||
usr_path = self.usr_regex.search(fname)
|
||||
if usr_path:
|
||||
# Run tests for /usr directory
|
||||
usr_file = usr_path.group(1)
|
||||
self._check_usr_standard_dir(usr_file, pkg, usr_list)
|
||||
continue
|
||||
|
||||
@staticmethod
|
||||
def _check_usr_std_dir(d, usr_list):
|
||||
var_path = self.var_regex.search(fname)
|
||||
if var_path:
|
||||
# Run tests for /var directory
|
||||
var_file = var_path.group(1)
|
||||
self._check_var_FSSTND_dir(var_file, pkg, var_list)
|
||||
self._check_var_standard_dir(var_file, pkg, var_list)
|
||||
|
||||
def _check_usr_standard_dir(self, usr_file, pkg, usr_list):
|
||||
"""
|
||||
Check if the file is in valid subdirectory of /usr.
|
||||
"""
|
||||
if d not in FHSCheck.usr_subdir and d not in usr_list:
|
||||
usr_list.append(d)
|
||||
return False
|
||||
return True
|
||||
|
||||
@staticmethod
|
||||
def _check_var_FSSTND_dir(d, var_list):
|
||||
"""
|
||||
Check if the file is not packaged in an obsolete (illegal) subdirectory of /var.
|
||||
"""
|
||||
if d in FHSCheck.var_fsstnd and d not in var_list:
|
||||
var_list.append(d)
|
||||
return False
|
||||
return True
|
||||
FHS 3.0 says: "Large software packages must not use a direct
|
||||
subdirectory under the /usr hierarchy." Check if this package contains
|
||||
a directory in /usr that is not mentioned in FHS (usr_list).
|
||||
|
||||
@staticmethod
|
||||
def _check_var_std_dir(d, var_list):
|
||||
Refer to http://refspecs.linuxfoundation.org/FHS_3.0/fhs/ch04.html for
|
||||
details.
|
||||
"""
|
||||
if usr_file not in FHSCheck.usr_subdir and usr_file not in usr_list:
|
||||
usr_list.append(usr_file)
|
||||
self.output.add_info('W', pkg, 'non-standard-dir-in-usr', usr_file)
|
||||
|
||||
def _check_var_FSSTND_dir(self, var_file, pkg, var_list):
|
||||
"""
|
||||
Check if the file is not packaged in an obsolete (illegal)
|
||||
subdirectory of /var.
|
||||
"""
|
||||
if var_file in FHSCheck.var_fsstnd and var_file not in var_list:
|
||||
var_list.append(var_file)
|
||||
self.output.add_info('W', pkg, 'FSSTND-dir-in-var', var_file)
|
||||
|
||||
def _check_var_standard_dir(self, var_file, pkg, var_list):
|
||||
"""
|
||||
Check if the file is in valid subdirectory of /var.
|
||||
|
||||
FHS 3.0 says: "Applications must generally not add directories to the
|
||||
top level of /var. Such directories should only be added if they have
|
||||
some system-wide implication, and in consultation with the FHS
|
||||
mailing list."
|
||||
|
||||
Refer to http://refspecs.linuxfoundation.org/FHS_3.0/fhs/ch05.htm
|
||||
for details.
|
||||
"""
|
||||
if d not in FHSCheck.var_subdir and d not in var_list:
|
||||
var_list.append(d)
|
||||
return False
|
||||
return True
|
||||
if var_file not in FHSCheck.var_subdir and var_file not in var_list:
|
||||
var_list.append(var_file)
|
||||
self.output.add_info('W', pkg, 'non-standard-dir-in-var', var_file)
|
||||
|
||||
|
||||
fhs_details_dict = {
|
||||
|
|
Loading…
Reference in New Issue