[Python-checkins] r61542 - in python/branches/release25-maint: Lib/test/test_posix.py Modules/posixmodule.c

gregory.p.smith python-checkins at python.org
Tue Mar 18 20:21:40 CET 2008


Author: gregory.p.smith
Date: Tue Mar 18 20:21:40 2008
New Revision: 61542
Modified:
 python/branches/release25-maint/Lib/test/test_posix.py
 python/branches/release25-maint/Modules/posixmodule.c
Log:
Backport r61450 from trunk:
 Fix chown on 64-bit linux. It needed to take a long (64-bit on 64bit linux) as
 uid and gid input to accept values >=2**31 as valid while still accepting
 negative numbers to pass -1 to chown for "no change".
 Fixes issue1747858.
Modified: python/branches/release25-maint/Lib/test/test_posix.py
==============================================================================
--- python/branches/release25-maint/Lib/test/test_posix.py	(original)
+++ python/branches/release25-maint/Lib/test/test_posix.py	Tue Mar 18 20:21:40 2008
@@ -9,6 +9,7 @@
 
 import time
 import os
+import pwd
 import sys
 import unittest
 import warnings
@@ -142,6 +143,33 @@
 if hasattr(posix, 'stat'):
 self.assert_(posix.stat(test_support.TESTFN))
 
+ if hasattr(posix, 'chown'):
+ def test_chown(self):
+ # raise an OSError if the file does not exist
+ os.unlink(test_support.TESTFN)
+ self.assertRaises(OSError, posix.chown, test_support.TESTFN, -1, -1)
+
+ # re-create the file
+ open(test_support.TESTFN, 'w').close()
+ if os.getuid() == 0:
+ try:
+ # Many linux distros have a nfsnobody user as MAX_UID-2
+ # that makes a good test case for signedness issues.
+ # http://bugs.python.org/issue1747858
+ # This part of the test only runs when run as root.
+ # Only scary people run their tests as root.
+ ent = pwd.getpwnam('nfsnobody')
+ posix.chown(test_support.TESTFN, ent.pw_uid, ent.pw_gid)
+ except KeyError:
+ pass
+ else:
+ # non-root cannot chown to root, raises OSError
+ self.assertRaises(OSError, posix.chown,
+ test_support.TESTFN, 0, 0)
+
+ # test a successful chown call
+ posix.chown(test_support.TESTFN, os.getuid(), os.getgid())
+
 def test_chdir(self):
 if hasattr(posix, 'chdir'):
 posix.chdir(os.curdir)
Modified: python/branches/release25-maint/Modules/posixmodule.c
==============================================================================
--- python/branches/release25-maint/Modules/posixmodule.c	(original)
+++ python/branches/release25-maint/Modules/posixmodule.c	Tue Mar 18 20:21:40 2008
@@ -1779,9 +1779,9 @@
 posix_chown(PyObject *self, PyObject *args)
 {
 	char *path = NULL;
-	int uid, gid;
+	long uid, gid;
 	int res;
-	if (!PyArg_ParseTuple(args, "etii:chown",
+	if (!PyArg_ParseTuple(args, "etll:chown",
 	 Py_FileSystemDefaultEncoding, &path,
 	 &uid, &gid))
 		return NULL;


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /