Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.
RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.

Bug 1659588

Summary: repotrack --repofrompath and --repoid parameters with -t or --tempcache options don't work as non-root user
Product: Red Hat Enterprise Linux 7 Reporter: afox <afox>
Component: yum-utilsAssignee: Michal Domonkos <mdomonko>
Status: CLOSED ERRATA QA Contact: Jan Blazek <jblazek>
Severity: high Docs Contact:
Priority: high    
Version: 7.6CC: kabbott, kwalker, mdomonko, mnk, packaging-team-maint
Target Milestone: rcKeywords: Triaged
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: yum-utils-1.1.31-53.el7 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2020-03-31 20:07:41 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
repotrack: Move the setCacheDir operation to after repofrompath none

Description afox@redhat.com 2018-12-14 18:01:15 UTC
Description of problem:
When repotrack --repofrompath and --repoid parameters with -t or --tempcache options are used by non-root user, then command fails with error. 

$ repotrack --repofrompath=oo,http://openopen.nam.nsroot.net/openopen/not-cert/rhel7-x86_64/latest/RPMS.all/ --repoid=oo --urls bash
Added oo repo from http://openopen.nam.nsroot.net/openopen/not-cert/rhel7-x86_64/latest/RPMS.all/
Traceback (most recent call last):
  File "/bin/repotrack", line 285, in <module>
    main()
  File "/bin/repotrack", line 197, in main
    my._getSacks(archlist=archlist)
  File "/usr/lib/python2.7/site-packages/yum/__init__.py", line 778, in _getSacks
    self.repos.populateSack(which=repos)
  File "/usr/lib/python2.7/site-packages/yum/repos.py", line 386, in populateSack
    sack.populate(repo, mdtype, callback, cacheonly)
  File "/usr/lib/python2.7/site-packages/yum/yumRepo.py", line 227, in populate
    if self._check_db_version(repo, mydbtype):
  File "/usr/lib/python2.7/site-packages/yum/yumRepo.py", line 319, in _check_db_version
    return repo._check_db_version(mdtype)
  File "/usr/lib/python2.7/site-packages/yum/yumRepo.py", line 1515, in _check_db_version
    repoXML = self.repoXML
  File "/usr/lib/python2.7/site-packages/yum/yumRepo.py", line 1701, in <lambda>
    repoXML = property(fget=lambda self: self._getRepoXML(),
  File "/usr/lib/python2.7/site-packages/yum/yumRepo.py", line 1697, in _getRepoXML
    self._loadRepoXML(text=self.ui_id)
  File "/usr/lib/python2.7/site-packages/yum/yumRepo.py", line 1688, in _loadRepoXML
    return self._groupLoadRepoXML(text, self._mdpolicy2mdtypes())
  File "/usr/lib/python2.7/site-packages/yum/yumRepo.py", line 1662, in _groupLoadRepoXML
    if self._commonLoadRepoXML(text):
  File "/usr/lib/python2.7/site-packages/yum/yumRepo.py", line 1477, in _commonLoadRepoXML
    if self._latestRepoXML(local):
  File "/usr/lib/python2.7/site-packages/yum/yumRepo.py", line 1446, in _latestRepoXML
    oxml = self._saveOldRepoXML(local)
  File "/usr/lib/python2.7/site-packages/yum/yumRepo.py", line 1303, in _saveOldRepoXML
    shutil.copy2(local, old_local)
  File "/usr/lib64/python2.7/shutil.py", line 130, in copy2
    copyfile(src, dst)
  File "/usr/lib64/python2.7/shutil.py", line 83, in copyfile
    with open(dst, 'wb') as fdst:
IOError: [Errno 13] Permission denied: '/var/cache/yum/x86_64/7Server/oo/repomd.xml.old.tmp'

$ repotrack --repofrompath=oo,http://openopen.nam.nsroot.net/openopen/not-cert/rhel7-x86_64/latest/RPMS.all/ --repoid=oo --urls --tempcache  bash
Added oo repo from http://openopen.nam.nsroot.net/openopen/not-cert/rhel7-x86_64/latest/RPMS.all/
Traceback (most recent call last):
  File "/bin/repotrack", line 285, in <module>
    main()
  File "/bin/repotrack", line 197, in main
    my._getSacks(archlist=archlist)
  File "/usr/lib/python2.7/site-packages/yum/__init__.py", line 778, in _getSacks
    self.repos.populateSack(which=repos)
  File "/usr/lib/python2.7/site-packages/yum/repos.py", line 386, in populateSack
    sack.populate(repo, mdtype, callback, cacheonly)
  File "/usr/lib/python2.7/site-packages/yum/yumRepo.py", line 227, in populate
    if self._check_db_version(repo, mydbtype):
  File "/usr/lib/python2.7/site-packages/yum/yumRepo.py", line 319, in _check_db_version
    return repo._check_db_version(mdtype)
  File "/usr/lib/python2.7/site-packages/yum/yumRepo.py", line 1515, in _check_db_version
    repoXML = self.repoXML
  File "/usr/lib/python2.7/site-packages/yum/yumRepo.py", line 1701, in <lambda>
    repoXML = property(fget=lambda self: self._getRepoXML(),
  File "/usr/lib/python2.7/site-packages/yum/yumRepo.py", line 1697, in _getRepoXML
    self._loadRepoXML(text=self.ui_id)
  File "/usr/lib/python2.7/site-packages/yum/yumRepo.py", line 1688, in _loadRepoXML
    return self._groupLoadRepoXML(text, self._mdpolicy2mdtypes())
  File "/usr/lib/python2.7/site-packages/yum/yumRepo.py", line 1662, in _groupLoadRepoXML
    if self._commonLoadRepoXML(text):
  File "/usr/lib/python2.7/site-packages/yum/yumRepo.py", line 1477, in _commonLoadRepoXML
    if self._latestRepoXML(local):
  File "/usr/lib/python2.7/site-packages/yum/yumRepo.py", line 1446, in _latestRepoXML
    oxml = self._saveOldRepoXML(local)
  File "/usr/lib/python2.7/site-packages/yum/yumRepo.py", line 1303, in _saveOldRepoXML
    shutil.copy2(local, old_local)
  File "/usr/lib64/python2.7/shutil.py", line 130, in copy2
    copyfile(src, dst)
  File "/usr/lib64/python2.7/shutil.py", line 83, in copyfile
    with open(dst, 'wb') as fdst:
IOError: [Errno 13] Permission denied: '/var/cache/yum/x86_64/7Server/oo/repomd.xml.old.tmp'

Version-Release number of selected component (if applicable):
yum-utils-1.1.31-50.el7 and above

How reproducible:
Always

Steps to Reproduce:
1. Run command as shown above in description 

Actual results:
IOError: [Errno 13] Permission denied: '/var/cache/yum/x86_64/7Server/oo/repomd.xml.old.tmp'

Expected results:
No error.

Comment 7 Kyle Walker 2019-07-10 17:36:23 UTC
Created attachment 1589175 [details]
repotrack: Move the setCacheDir operation to after  repofrompath

On further inspection, it looks like this should be pretty simple to fix... The difficulty is the following:

    # do the happy tmpdir thing if we're not root
    if os.geteuid() != 0 or opts.tempcache:
        cachedir = getCacheDir()
        if cachedir is None:
            print >> sys.stderr, "Error: Could not make cachedir, exiting"
            sys.exit(50)

        my.repos.setCacheDir(cachedir)


This creates a temporary cache directory named for the current user.

    $ ll /var/tmp/yum-vagrant-Fl8ySL/


However, the key to the problem is that EPERM is coming from the /var/cache/yum/ directory.

    IOError: [Errno 13] Permission denied: '/var/cache/yum/x86_64/7Server/oo/repomd.xml.old.tmp'


This is due to the above cachedir variable not being applied to repofrompath repos in subsequent operations:

    if opts.repofrompath:
        for repo in opts.repofrompath:
            tmp = tuple(repo.split(','))
            if len(tmp) != 2:
                my.logger.error("Error: Bad repofrompath argument: %s" %repo)
                continue
            repoid, repopath = tmp
            if repopath and repopath[0] == '/':
                baseurl = 'file://' + repopath
            else:
                baseurl = repopath
            try:
                my.add_enable_repo(repoid, baseurls=[baseurl],
                                   basecachedir=my.conf.cachedir,
                                   timestamp_check=False)
            except yum.Errors.DuplicateRepoError, e:
                my.logger.error(e)
                sys.exit(1)
            if not opts.quiet:
                my.logger.info("Added %s repo from %s" % (repoid, repopath))



I've attached a patch that fixes the condition.

Comment 19 errata-xmlrpc 2020-03-31 20:07:41 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2020:1158