Bug 166485 - rpm-python fails to open a transaction set with a given relative root path
rpm-python fails to open a transaction set with a given relative root path
Status: CLOSED WORKSFORME
Product: Fedora
Classification: Fedora
Component: rpm (Show other bugs)
4
All Linux
medium Severity medium
: ---
: ---
Assigned To: Paul Nasrat
Mike McLean
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2005-08-22 08:21 EDT by Antonio Alvarado Hernández
Modified: 2007-11-30 17:11 EST (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2005-08-28 07:34:38 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Antonio Alvarado Hernández 2005-08-22 08:21:17 EDT
Description of problem:

In rpm-python bindings, when I create a TransactionSet instance passing a
relative root path to the constructor, dbMatch fails with an errno = 2 (No such
file or directory).

Version-Release number of selected component (if applicable):

$ rpm -q rpm-python
rpm-python-4.4.1-21

How reproducible:

Always

Steps to Reproduce:

1. $ mkdir -p /tmp/root
2. $ mkdir -p /tmp/root/var/lib
3. $ cp -a /var/lib/rpm /tmp/root/var/lib/rpm
4. $ cd /tmp
5. $ cat <<EOT > testrpm.py
#!/usr/bin/python

import sys
import rpm

def main( args ):
        print "Begining..."
        ts = rpm.TransactionSet( 'root' )
        it = ts.dbMatch( 'provides', 'redhat-release' )
        print "Finished!"

if __name__ == '__main__':
        main( sys.argv[1:0] )
EOT
6. $ chmod 0755 testrpm.py
7. $ ./testrpm.py
Begining...
error: cannot open Packages index using db3 - No such file or directory (2)
error: cannot open Packages database in root/var/lib/rpm
Traceback (most recent call last):
  File "./testrpm.py", line 13, in ?
    main( sys.argv[1:0] )
  File "./testrpm.py", line 9, in main
    it = ts.dbMatch( 'provides', 'redhat-release' )
TypeError: rpmdb open failed
8. $ vi testrpm.py
... changing 'root' by '/tmp/root' ...
9. $ ./testrpm.py
Begining...
Finished!

Actual results:

Begining...
error: cannot open Packages index using db3 - No such file or directory (2)
error: cannot open Packages database in root/var/lib/rpm
Traceback (most recent call last):
  File "./testrpm.py", line 13, in ?
    main( sys.argv[1:0] )
  File "./testrpm.py", line 9, in main
    it = ts.dbMatch( 'provides', 'redhat-release' )
TypeError: rpmdb open failed

Expected results:

Begining...
Finished!

Additional info:

Following a strace of given testcase code:

$ strace -e trace=file ./testrpm.py 2>&1 | fgrep stat64 | fgrep 'root/var/lib/rpm'
stat64("root/var/lib/rpm", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
stat64("root/var/lib/rpm/DB_CONFIG", 0xbf969d3c) = -1 ENOENT (No such file or
directory)
stat64("root/var/lib/rpm/__db.001", {st_mode=S_IFREG|0644, st_size=24576, ...}) = 0
stat64("root/var/lib/rpm/__db.002", {st_mode=S_IFREG|0644, st_size=1318912,
...}) = 0
stat64("root/var/lib/rpm/__db.003", {st_mode=S_IFREG|0644, st_size=450560, ...}) = 0
stat64("root/var/lib/rpm/root/var/lib/rpm/Packages", 0xbf969bdc) = -1 ENOENT (No
such file or directory)
stat64("root/var/lib/rpm/root/var/lib/rpm/Packages", 0xbf969c3c) = -1 ENOENT (No
such file or directory)
Comment 1 Jeff Johnson 2005-08-25 12:45:17 EDT
This is a misuse of rpm.TransactionSet() (otherwise known as programmer error).

OTOH, it wouldn't be impossibly hard to turn the relative path into an absolute path
within the bindings. I'm not quite sure that's worth the effort however.
Comment 2 Florian La Roche 2005-08-25 14:47:21 EDT
Just call os.path.abspath() before passing data to rpm.

Note You need to log in before you can comment on or make changes to this bug.