Author: Ronan Lamy <[email protected]>
Branch: follow_symlinks
Changeset: r83326:8ecd99407360
Date: 2016-03-25 00:36 +0000
http://bitbucket.org/pypy/pypy/changeset/8ecd99407360/
Log: hg merge rposix-for-3
diff --git a/rpython/rlib/rposix.py b/rpython/rlib/rposix.py
--- a/rpython/rlib/rposix.py
+++ b/rpython/rlib/rposix.py
@@ -1739,6 +1739,7 @@
AT_SYMLINK_NOFOLLOW =
rffi_platform.DefinedConstantInteger('AT_SYMLINK_NOFOLLOW')
AT_EACCESS = rffi_platform.DefinedConstantInteger('AT_EACCESS')
AT_REMOVEDIR = rffi_platform.DefinedConstantInteger('AT_REMOVEDIR')
+ AT_EMPTY_PATH = rffi_platform.DefinedConstantInteger('AT_EMPTY_PATH')
UTIME_NOW = rffi_platform.DefinedConstantInteger('UTIME_NOW')
UTIME_OMIT = rffi_platform.DefinedConstantInteger('UTIME_OMIT')
TIMESPEC = rffi_platform.Struct('struct timespec', [
@@ -1772,6 +1773,34 @@
error = c_faccessat(dir_fd, pathname, mode, flags)
return error == 0
+if HAVE_FCHMODAT:
+ c_fchmodat = external('fchmodat',
+ [rffi.INT, rffi.CCHARP, rffi.INT, rffi.INT], rffi.INT,
+ save_err=rffi.RFFI_SAVE_ERRNO,)
+
+ def fchmodat(path, mode, dir_fd=AT_FDCWD, follow_symlinks=True):
+ if follow_symlinks:
+ flag = 0
+ else:
+ flag = AT_SYMLINK_NOFOLLOW
+ error = c_fchmodat(dir_fd, path, mode, flag)
+ handle_posix_error('fchmodat', error)
+
+if HAVE_FCHOWNAT:
+ c_fchownat = external('fchownat',
+ [rffi.INT, rffi.CCHARP, rffi.INT, rffi.INT, rffi.INT], rffi.INT,
+ save_err=rffi.RFFI_SAVE_ERRNO,)
+
+ def fchownat(path, owner, group, dir_fd=AT_FDCWD,
+ follow_symlinks=True, empty_path=False):
+ flag = 0
+ if not follow_symlinks:
+ flag |= AT_SYMLINK_NOFOLLOW
+ if empty_path:
+ flag |= AT_EMPTY_PATH
+ error = c_fchownat(dir_fd, path, owner, group, flag)
+ handle_posix_error('fchownat', error)
+
if HAVE_LINKAT:
c_linkat = external('linkat',
[rffi.INT, rffi.CCHARP, rffi.INT, rffi.CCHARP, rffi.INT], rffi.INT)
@@ -1876,11 +1905,11 @@
if HAVE_SYMLINKAT:
c_symlinkat = external('symlinkat',
- [rffi.CCHARP, rffi.CCHARP, rffi.INT], rffi.INT,
+ [rffi.CCHARP, rffi.INT, rffi.CCHARP], rffi.INT,
save_err=rffi.RFFI_SAVE_ERRNO)
def symlinkat(src, dst, dir_fd=AT_FDCWD):
- error = c_symlinkat(src, dst, dir_fd)
+ error = c_symlinkat(src, dir_fd, dst)
handle_posix_error('symlinkat', error)
if HAVE_OPENAT:
diff --git a/rpython/rlib/test/test_rposix.py b/rpython/rlib/test/test_rposix.py
--- a/rpython/rlib/test/test_rposix.py
+++ b/rpython/rlib/test/test_rposix.py
@@ -508,6 +508,16 @@
finally:
os.close(dirfd)
+ def test_fchmodat(self):
+ def f(dirfd):
+ return rposix.fchmodat('test_open_ascii', 0777, dirfd)
+
+ dirfd = os.open(os.path.dirname(self.ufilename), os.O_RDONLY)
+ try:
+ interpret(f, [dirfd]) # does not crash
+ finally:
+ os.close(dirfd)
+
class TestPosixUnicode(BasePosixUnicodeOrAscii):
def _get_filename(self):
@@ -526,3 +536,12 @@
os.open('/tmp/t', 0, 0)
os.open(u'/tmp/t', 0, 0)
compile(f, ())
+
+def test_symlinkat(tmpdir):
+ tmpdir.join('file').write('text')
+ dirfd = os.open(str(tmpdir), os.O_RDONLY)
+ try:
+ rposix.symlinkat('file', 'link', dir_fd=dirfd)
+ assert os.readlink(str(tmpdir.join('link'))) == 'file'
+ finally:
+ os.close(dirfd)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit