mirror of
https://github.com/python/cpython.git
synced 2025-09-27 02:39:58 +00:00
bpo-18108: Adding dir_fd and follow_symlinks keyword args to shutil.chown (GH-15811)
* Adding dir_fd and follow_symlinks keyword args to shutil.chown * Extending test_shutil.TestShutil.test_chown to include new kwargs * Updating shutil.chown documentation Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> Co-authored-by: Berker Peksag <berker.peksag@gmail.com> Co-authored-by: Zachary Ware <zachary.ware@gmail.com>
This commit is contained in:
parent
78ba4cb758
commit
8974a63f5e
5 changed files with 53 additions and 4 deletions
|
@ -2212,7 +2212,9 @@ class TestMisc(BaseTest, unittest.TestCase):
|
|||
def test_chown(self):
|
||||
dirname = self.mkdtemp()
|
||||
filename = tempfile.mktemp(dir=dirname)
|
||||
linkname = os.path.join(dirname, "chown_link")
|
||||
write_file(filename, 'testing chown function')
|
||||
os.symlink(filename, linkname)
|
||||
|
||||
with self.assertRaises(ValueError):
|
||||
shutil.chown(filename)
|
||||
|
@ -2233,7 +2235,7 @@ class TestMisc(BaseTest, unittest.TestCase):
|
|||
gid = os.getgid()
|
||||
|
||||
def check_chown(path, uid=None, gid=None):
|
||||
s = os.stat(filename)
|
||||
s = os.stat(path)
|
||||
if uid is not None:
|
||||
self.assertEqual(uid, s.st_uid)
|
||||
if gid is not None:
|
||||
|
@ -2269,6 +2271,36 @@ class TestMisc(BaseTest, unittest.TestCase):
|
|||
shutil.chown(dirname, user, group)
|
||||
check_chown(dirname, uid, gid)
|
||||
|
||||
dirfd = os.open(dirname, os.O_RDONLY)
|
||||
self.addCleanup(os.close, dirfd)
|
||||
basename = os.path.basename(filename)
|
||||
baselinkname = os.path.basename(linkname)
|
||||
shutil.chown(basename, uid, gid, dir_fd=dirfd)
|
||||
check_chown(filename, uid, gid)
|
||||
shutil.chown(basename, uid, dir_fd=dirfd)
|
||||
check_chown(filename, uid)
|
||||
shutil.chown(basename, group=gid, dir_fd=dirfd)
|
||||
check_chown(filename, gid=gid)
|
||||
shutil.chown(basename, uid, gid, dir_fd=dirfd, follow_symlinks=True)
|
||||
check_chown(filename, uid, gid)
|
||||
shutil.chown(basename, uid, gid, dir_fd=dirfd, follow_symlinks=False)
|
||||
check_chown(filename, uid, gid)
|
||||
shutil.chown(linkname, uid, follow_symlinks=True)
|
||||
check_chown(filename, uid)
|
||||
shutil.chown(baselinkname, group=gid, dir_fd=dirfd, follow_symlinks=False)
|
||||
check_chown(filename, gid=gid)
|
||||
shutil.chown(baselinkname, uid, gid, dir_fd=dirfd, follow_symlinks=True)
|
||||
check_chown(filename, uid, gid)
|
||||
|
||||
with self.assertRaises(TypeError):
|
||||
shutil.chown(filename, uid, dir_fd=dirname)
|
||||
|
||||
with self.assertRaises(FileNotFoundError):
|
||||
shutil.chown('missingfile', uid, gid, dir_fd=dirfd)
|
||||
|
||||
with self.assertRaises(ValueError):
|
||||
shutil.chown(filename, dir_fd=dirfd)
|
||||
|
||||
|
||||
@support.requires_subprocess()
|
||||
class TestWhich(BaseTest, unittest.TestCase):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue