• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

rpm-software-management / rpmlint / 16417707174

21 Jul 2025 01:02PM UTC coverage: 87.143% (-0.04%) from 87.181%
16417707174

push

github

5883 of 6751 relevant lines covered (87.14%)

3.4 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/rpmlint/checks/BuildRootAndDateCheck.py
1
import re
4✔
2
import stat
4✔
3
import time
4✔
4

5
import rpm
4✔
6
from rpmlint.checks.AbstractCheck import AbstractFilesCheck
4✔
7

8

9
class BuildRootAndDateCheck(AbstractFilesCheck):
4✔
10
    """
11
    Check that the file doesn't contain the current date or time.
12
    And check the file does not contain build root reference.
13

14
    If so, it causes the package to rebuild when it's not needed.
15
    """
16
    def __init__(self, config, output):
4✔
17
        super().__init__(config, output, r'.*')
4✔
18
        self.looksliketime = re.compile('(2[0-3]|[01]?[0-9]):([0-5]?[0-9]):([0-5]?[0-9])')
4✔
19
        self.istoday = re.compile(time.strftime('%b %e %Y'))
4✔
20
        # in rpm 4.20 the expandMacro will return an empty string and so we run
4✔
21
        # into the "or" case.
22
        # return a string that is modelled after the actual path that rpm 4.20
4✔
23
        # is using so we can actually match what the rpm 4.20 path will be and
4✔
24
        # not just any random string in a file that references buildroot.
4✔
25
        # https://github.com/rpm-software-management/rpm/blob/rpm-4.20.1-release/build/parsePreamble.c#L1290
4✔
26
        self.prepare_regex(rpm.expandMacro('%{?buildroot}') or '/%{NAME}-%{VERSION}-build/BUILDROOT/')
27

4✔
28
    def prepare_regex(self, buildroot):
4✔
29
        for m in ('name', 'version', 'release', 'NAME', 'VERSION', 'RELEASE'):
30
            buildroot = buildroot.replace('%%{%s}' % (m), r'[\w\!-\.]{1,20}')
2✔
31
        self.lookslikebuildroot = re.compile(buildroot)
32

4✔
33
    def check_file(self, pkg, filename):
4✔
34
        if filename.startswith('/usr/lib/debug') or pkg.is_source or \
4✔
35
                not stat.S_ISREG(pkg.files[filename].mode):
4✔
36
            return
37

4✔
38
        data = pkg.read_with_mmap(filename)
4✔
39
        if self.istoday.search(data):
4✔
40
            if self.looksliketime.search(data):
41
                self.output.add_info('E', pkg, 'file-contains-date-and-time', filename)
42
            else:
43
                self.output.add_info('E', pkg, 'file-contains-current-date', filename)
44
        if self.lookslikebuildroot.search(data):
45
            self.output.add_info('E', pkg, 'file-contains-buildroot', filename)
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc