[Yum-devel] [PATCH] Use os.open instead of open

Zdeněk Pavlas zpavlas at redhat.com
Thu Sep 29 07:14:16 UTC 2011


Builtin open() function works only with files.
We should start reading logger.critical messages.

>>> os.open('.', os.O_RDONLY)
3
>>> open('.')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IOError: [Errno 21] Is a directory: '.'
---
 yummain.py |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/yummain.py b/yummain.py
index 4b1112a..05e888d 100755
--- a/yummain.py
+++ b/yummain.py
@@ -101,16 +101,16 @@ def main(args):
     except Errors.YumBaseError, e:
         return exFatal(e)
 
-    # Try to open the current directory to see if we have 
-    # read and write access. If not, chdir to /
+    # A hack to prevent BZ 698795.
+    # Check if RPM can open the current directory, else chdir to /
     try:
-        f = open(".")
+        f = os.open(".", os.O_RDONLY)
     except IOError, e:
         if e.errno == errno.EACCES:
-            logger.critical(_('No read/write access in current directory, moving to /'))
+            logger.critical(_('Can not open current directory, moving to /'))
             os.chdir("/")
     else:
-        close(f)
+        os.close(f)
 
     lockerr = ""
     while True:
-- 
1.7.4.4



More information about the Yum-devel mailing list