[pypy-svn] r79993 - in pypy/branch/more-posix/pypy: rpython/module translator/c/test

arigo at codespeak.net arigo at codespeak.net
Sat Dec 11 18:05:00 CET 2010


Author: arigo
Date: Sat Dec 11 18:04:58 2010
New Revision: 79993

Modified:
   pypy/branch/more-posix/pypy/rpython/module/ll_os.py
   pypy/branch/more-posix/pypy/translator/c/test/test_extfunc.py
Log:
Translation of os.lchown().


Modified: pypy/branch/more-posix/pypy/rpython/module/ll_os.py
==============================================================================
--- pypy/branch/more-posix/pypy/rpython/module/ll_os.py	(original)
+++ pypy/branch/more-posix/pypy/rpython/module/ll_os.py	Sat Dec 11 18:04:58 2010
@@ -1129,6 +1129,19 @@
         return extdef([str, int, int], None, "ll_os.ll_os_chown",
                       llimpl=os_chown_llimpl)
 
+    @registering_if(os, 'lchown')
+    def register_os_lchown(self):
+        os_lchown = self.llexternal('lchown',[rffi.CCHARP, rffi.INT, rffi.INT],
+                                    rffi.INT)
+
+        def os_lchown_llimpl(path, uid, gid):
+            res = os_lchown(path, uid, gid)
+            if res == -1:
+                raise OSError(rposix.get_errno(), "os_lchown failed")
+
+        return extdef([str, int, int], None, "ll_os.ll_os_lchown",
+                      llimpl=os_lchown_llimpl)
+
     @registering_if(os, 'readlink')
     def register_os_readlink(self):
         os_readlink = self.llexternal('readlink',

Modified: pypy/branch/more-posix/pypy/translator/c/test/test_extfunc.py
==============================================================================
--- pypy/branch/more-posix/pypy/translator/c/test/test_extfunc.py	(original)
+++ pypy/branch/more-posix/pypy/translator/c/test/test_extfunc.py	Sat Dec 11 18:04:58 2010
@@ -539,6 +539,28 @@
         # for what reason do they want us to shift by 8? See the doc
         assert status1 >> 8 == 4
 
+if hasattr(os, 'chown') and hasattr(os, 'lchown'):
+    def test_os_chown_lchown():
+        path1 = udir.join('test_os_chown_lchown-1.txt')
+        path2 = udir.join('test_os_chown_lchown-2.txt')
+        path1.write('foobar')
+        path2.mksymlinkto('some-broken-symlink')
+        tmpfile1 = str(path1)
+        tmpfile2 = str(path2)
+        def does_stuff():
+            # xxx not really a test, just checks that they are callable
+            os.chown(tmpfile1, os.getuid(), os.getgid())
+            os.lchown(tmpfile1, os.getuid(), os.getgid())
+            os.lchown(tmpfile2, os.getuid(), os.getgid())
+            try:
+                os.chown(tmpfile2, os.getuid(), os.getgid())
+            except OSError:
+                pass
+            else:
+                raise AssertionError("os.chown(broken symlink) should raise")
+        f1 = compile(does_stuff, [])
+        f1()
+
 # ____________________________________________________________
 
 def _real_getenv(var):



More information about the Pypy-commit mailing list