mirror of
https://github.com/python/cpython.git
synced 2025-07-29 14:15:07 +00:00
Patch #1490190: posixmodule now includes os.chflags() and os.lchflags()
functions on platforms where the underlying system calls are available.
This commit is contained in:
parent
0713a68dc5
commit
382abeff0f
11 changed files with 133 additions and 10 deletions
|
@ -758,6 +758,26 @@ Availability: Macintosh, \UNIX, Windows.
|
||||||
\versionadded{2.3}
|
\versionadded{2.3}
|
||||||
\end{funcdesc}
|
\end{funcdesc}
|
||||||
|
|
||||||
|
\begin{funcdesc}{chflags}{path, flags}
|
||||||
|
Set the flags of \var{path} to the numeric \var{flags}.
|
||||||
|
\var{flags} may take a combination (bitwise OR) of the following values
|
||||||
|
(as defined in the \module{stat} module):
|
||||||
|
\begin{itemize}
|
||||||
|
\item \code{UF_NODUMP}
|
||||||
|
\item \code{UF_IMMUTABLE}
|
||||||
|
\item \code{UF_APPEND}
|
||||||
|
\item \code{UF_OPAQUE}
|
||||||
|
\item \code{UF_NOUNLINK}
|
||||||
|
\item \code{SF_ARCHIVED}
|
||||||
|
\item \code{SF_IMMUTABLE}
|
||||||
|
\item \code{SF_APPEND}
|
||||||
|
\item \code{SF_NOUNLINK}
|
||||||
|
\item \code{SF_SNAPSHOT}
|
||||||
|
\end{itemize}
|
||||||
|
Availability: Macintosh, \UNIX.
|
||||||
|
\versionadded{2.6}
|
||||||
|
\end{funcdesc}
|
||||||
|
|
||||||
\begin{funcdesc}{chroot}{path}
|
\begin{funcdesc}{chroot}{path}
|
||||||
Change the root directory of the current process to \var{path}.
|
Change the root directory of the current process to \var{path}.
|
||||||
Availability: Macintosh, \UNIX.
|
Availability: Macintosh, \UNIX.
|
||||||
|
@ -804,6 +824,13 @@ and \var{gid}. To leave one of the ids unchanged, set it to -1.
|
||||||
Availability: Macintosh, \UNIX.
|
Availability: Macintosh, \UNIX.
|
||||||
\end{funcdesc}
|
\end{funcdesc}
|
||||||
|
|
||||||
|
\begin{funcdesc}{lchflags}{path, flags}
|
||||||
|
Set the flags of \var{path} to the numeric \var{flags}, like
|
||||||
|
\function{chflags()}, but do not follow symbolic links.
|
||||||
|
Availability: \UNIX.
|
||||||
|
\versionadded{2.6}
|
||||||
|
\end{funcdesc}
|
||||||
|
|
||||||
\begin{funcdesc}{lchown}{path, uid, gid}
|
\begin{funcdesc}{lchown}{path, uid, gid}
|
||||||
Change the owner and group id of \var{path} to the numeric \var{uid}
|
Change the owner and group id of \var{path} to the numeric \var{uid}
|
||||||
and gid. This function will not follow symbolic links.
|
and gid. This function will not follow symbolic links.
|
||||||
|
|
|
@ -44,8 +44,8 @@ file type and creator codes will not be correct.
|
||||||
\end{funcdesc}
|
\end{funcdesc}
|
||||||
|
|
||||||
\begin{funcdesc}{copystat}{src, dst}
|
\begin{funcdesc}{copystat}{src, dst}
|
||||||
Copy the permission bits, last access time, and last modification
|
Copy the permission bits, last access time, last modification time,
|
||||||
time from \var{src} to \var{dst}. The file contents, owner, and
|
and flags from \var{src} to \var{dst}. The file contents, owner, and
|
||||||
group are unaffected. \var{src} and \var{dst} are path names given
|
group are unaffected. \var{src} and \var{dst} are path names given
|
||||||
as strings.
|
as strings.
|
||||||
\end{funcdesc}
|
\end{funcdesc}
|
||||||
|
|
|
@ -60,13 +60,15 @@ def copymode(src, dst):
|
||||||
os.chmod(dst, mode)
|
os.chmod(dst, mode)
|
||||||
|
|
||||||
def copystat(src, dst):
|
def copystat(src, dst):
|
||||||
"""Copy all stat info (mode bits, atime and mtime) from src to dst"""
|
"""Copy all stat info (mode bits, atime, mtime, flags) from src to dst"""
|
||||||
st = os.stat(src)
|
st = os.stat(src)
|
||||||
mode = stat.S_IMODE(st.st_mode)
|
mode = stat.S_IMODE(st.st_mode)
|
||||||
if hasattr(os, 'utime'):
|
if hasattr(os, 'utime'):
|
||||||
os.utime(dst, (st.st_atime, st.st_mtime))
|
os.utime(dst, (st.st_atime, st.st_mtime))
|
||||||
if hasattr(os, 'chmod'):
|
if hasattr(os, 'chmod'):
|
||||||
os.chmod(dst, mode)
|
os.chmod(dst, mode)
|
||||||
|
if hasattr(os, 'chflags') and hasattr(st, 'st_flags'):
|
||||||
|
os.chflags(dst, st.st_flags)
|
||||||
|
|
||||||
|
|
||||||
def copy(src, dst):
|
def copy(src, dst):
|
||||||
|
|
13
Lib/stat.py
13
Lib/stat.py
|
@ -84,3 +84,16 @@ S_IRWXO = 00007
|
||||||
S_IROTH = 00004
|
S_IROTH = 00004
|
||||||
S_IWOTH = 00002
|
S_IWOTH = 00002
|
||||||
S_IXOTH = 00001
|
S_IXOTH = 00001
|
||||||
|
|
||||||
|
# Names for file flags
|
||||||
|
|
||||||
|
UF_NODUMP = 0x00000001
|
||||||
|
UF_IMMUTABLE = 0x00000002
|
||||||
|
UF_APPEND = 0x00000004
|
||||||
|
UF_OPAQUE = 0x00000008
|
||||||
|
UF_NOUNLINK = 0x00000010
|
||||||
|
SF_ARCHIVED = 0x00010000
|
||||||
|
SF_IMMUTABLE = 0x00020000
|
||||||
|
SF_APPEND = 0x00040000
|
||||||
|
SF_NOUNLINK = 0x00100000
|
||||||
|
SF_SNAPSHOT = 0x00200000
|
||||||
|
|
|
@ -192,6 +192,18 @@ class PosixTester(unittest.TestCase):
|
||||||
posix.utime(test_support.TESTFN, (int(now), int(now)))
|
posix.utime(test_support.TESTFN, (int(now), int(now)))
|
||||||
posix.utime(test_support.TESTFN, (now, now))
|
posix.utime(test_support.TESTFN, (now, now))
|
||||||
|
|
||||||
|
def test_chflags(self):
|
||||||
|
if hasattr(posix, 'chflags'):
|
||||||
|
st = os.stat(test_support.TESTFN)
|
||||||
|
if hasattr(st, 'st_flags'):
|
||||||
|
posix.chflags(test_support.TESTFN, st.st_flags)
|
||||||
|
|
||||||
|
def test_lchflags(self):
|
||||||
|
if hasattr(posix, 'lchflags'):
|
||||||
|
st = os.stat(test_support.TESTFN)
|
||||||
|
if hasattr(st, 'st_flags'):
|
||||||
|
posix.lchflags(test_support.TESTFN, st.st_flags)
|
||||||
|
|
||||||
def test_main():
|
def test_main():
|
||||||
test_support.run_unittest(PosixTester)
|
test_support.run_unittest(PosixTester)
|
||||||
|
|
||||||
|
|
|
@ -377,6 +377,7 @@ Luc Lefebvre
|
||||||
Kip Lehman
|
Kip Lehman
|
||||||
Joerg Lehmann
|
Joerg Lehmann
|
||||||
Marc-Andre Lemburg
|
Marc-Andre Lemburg
|
||||||
|
Mark Levinson
|
||||||
William Lewis
|
William Lewis
|
||||||
Robert van Liere
|
Robert van Liere
|
||||||
Martin Ligr
|
Martin Ligr
|
||||||
|
|
|
@ -371,6 +371,9 @@ Library
|
||||||
Extension Modules
|
Extension Modules
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
|
- Patch #1490190: posixmodule now includes os.chflags() and os.lchflags()
|
||||||
|
functions on platforms where the underlying system calls are available.
|
||||||
|
|
||||||
- Patch #1494140: Add documentation for the new struct.Struct object.
|
- Patch #1494140: Add documentation for the new struct.Struct object.
|
||||||
|
|
||||||
- Patch #1432399: Support the HCI protocol for bluetooth sockets
|
- Patch #1432399: Support the HCI protocol for bluetooth sockets
|
||||||
|
|
|
@ -1692,6 +1692,57 @@ posix_chmod(PyObject *self, PyObject *args)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef HAVE_CHFLAGS
|
||||||
|
PyDoc_STRVAR(posix_chflags__doc__,
|
||||||
|
"chflags(path, flags)\n\n\
|
||||||
|
Set file flags.");
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
posix_chflags(PyObject *self, PyObject *args)
|
||||||
|
{
|
||||||
|
char *path;
|
||||||
|
unsigned long flags;
|
||||||
|
int res;
|
||||||
|
if (!PyArg_ParseTuple(args, "etk:chflags",
|
||||||
|
Py_FileSystemDefaultEncoding, &path, &flags))
|
||||||
|
return NULL;
|
||||||
|
Py_BEGIN_ALLOW_THREADS
|
||||||
|
res = chflags(path, flags);
|
||||||
|
Py_END_ALLOW_THREADS
|
||||||
|
if (res < 0)
|
||||||
|
return posix_error_with_allocated_filename(path);
|
||||||
|
PyMem_Free(path);
|
||||||
|
Py_INCREF(Py_None);
|
||||||
|
return Py_None;
|
||||||
|
}
|
||||||
|
#endif /* HAVE_CHFLAGS */
|
||||||
|
|
||||||
|
#ifdef HAVE_LCHFLAGS
|
||||||
|
PyDoc_STRVAR(posix_lchflags__doc__,
|
||||||
|
"lchflags(path, flags)\n\n\
|
||||||
|
Set file flags.\n\
|
||||||
|
This function will not follow symbolic links.");
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
posix_lchflags(PyObject *self, PyObject *args)
|
||||||
|
{
|
||||||
|
char *path;
|
||||||
|
unsigned long flags;
|
||||||
|
int res;
|
||||||
|
if (!PyArg_ParseTuple(args, "etk:lchflags",
|
||||||
|
Py_FileSystemDefaultEncoding, &path, &flags))
|
||||||
|
return NULL;
|
||||||
|
Py_BEGIN_ALLOW_THREADS
|
||||||
|
res = lchflags(path, flags);
|
||||||
|
Py_END_ALLOW_THREADS
|
||||||
|
if (res < 0)
|
||||||
|
return posix_error_with_allocated_filename(path);
|
||||||
|
PyMem_Free(path);
|
||||||
|
Py_INCREF(Py_None);
|
||||||
|
return Py_None;
|
||||||
|
}
|
||||||
|
#endif /* HAVE_LCHFLAGS */
|
||||||
|
|
||||||
#ifdef HAVE_CHROOT
|
#ifdef HAVE_CHROOT
|
||||||
PyDoc_STRVAR(posix_chroot__doc__,
|
PyDoc_STRVAR(posix_chroot__doc__,
|
||||||
"chroot(path)\n\n\
|
"chroot(path)\n\n\
|
||||||
|
@ -8081,10 +8132,16 @@ static PyMethodDef posix_methods[] = {
|
||||||
{"ttyname", posix_ttyname, METH_VARARGS, posix_ttyname__doc__},
|
{"ttyname", posix_ttyname, METH_VARARGS, posix_ttyname__doc__},
|
||||||
#endif
|
#endif
|
||||||
{"chdir", posix_chdir, METH_VARARGS, posix_chdir__doc__},
|
{"chdir", posix_chdir, METH_VARARGS, posix_chdir__doc__},
|
||||||
|
#ifdef HAVE_CHFLAGS
|
||||||
|
{"chflags", posix_chflags, METH_VARARGS, posix_chflags__doc__},
|
||||||
|
#endif /* HAVE_CHFLAGS */
|
||||||
{"chmod", posix_chmod, METH_VARARGS, posix_chmod__doc__},
|
{"chmod", posix_chmod, METH_VARARGS, posix_chmod__doc__},
|
||||||
#ifdef HAVE_CHOWN
|
#ifdef HAVE_CHOWN
|
||||||
{"chown", posix_chown, METH_VARARGS, posix_chown__doc__},
|
{"chown", posix_chown, METH_VARARGS, posix_chown__doc__},
|
||||||
#endif /* HAVE_CHOWN */
|
#endif /* HAVE_CHOWN */
|
||||||
|
#ifdef HAVE_LCHFLAGS
|
||||||
|
{"lchflags", posix_lchflags, METH_VARARGS, posix_lchflags__doc__},
|
||||||
|
#endif /* HAVE_LCHFLAGS */
|
||||||
#ifdef HAVE_LCHOWN
|
#ifdef HAVE_LCHOWN
|
||||||
{"lchown", posix_lchown, METH_VARARGS, posix_lchown__doc__},
|
{"lchown", posix_lchown, METH_VARARGS, posix_lchown__doc__},
|
||||||
#endif /* HAVE_LCHOWN */
|
#endif /* HAVE_LCHOWN */
|
||||||
|
|
10
configure
vendored
10
configure
vendored
|
@ -1,5 +1,5 @@
|
||||||
#! /bin/sh
|
#! /bin/sh
|
||||||
# From configure.in Revision: 52843 .
|
# From configure.in Revision: 53508 .
|
||||||
# Guess values for system-dependent variables and create Makefiles.
|
# Guess values for system-dependent variables and create Makefiles.
|
||||||
# Generated by GNU Autoconf 2.59 for python 2.6.
|
# Generated by GNU Autoconf 2.59 for python 2.6.
|
||||||
#
|
#
|
||||||
|
@ -14718,11 +14718,13 @@ echo "${ECHO_T}MACHDEP_OBJS" >&6
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
for ac_func in alarm bind_textdomain_codeset chown clock confstr ctermid \
|
|
||||||
execv fork fpathconf ftime ftruncate \
|
|
||||||
|
for ac_func in alarm bind_textdomain_codeset chflags chown clock confstr \
|
||||||
|
ctermid execv fork fpathconf ftime ftruncate \
|
||||||
gai_strerror getgroups getlogin getloadavg getpeername getpgid getpid \
|
gai_strerror getgroups getlogin getloadavg getpeername getpgid getpid \
|
||||||
getpriority getpwent getspnam getspent getsid getwd \
|
getpriority getpwent getspnam getspent getsid getwd \
|
||||||
kill killpg lchown lstat mkfifo mknod mktime \
|
kill killpg lchflags lchown lstat mkfifo mknod mktime \
|
||||||
mremap nice pathconf pause plock poll pthread_init \
|
mremap nice pathconf pause plock poll pthread_init \
|
||||||
putenv readlink realpath \
|
putenv readlink realpath \
|
||||||
select setegid seteuid setgid \
|
select setegid seteuid setgid \
|
||||||
|
|
|
@ -2282,11 +2282,11 @@ fi
|
||||||
AC_MSG_RESULT(MACHDEP_OBJS)
|
AC_MSG_RESULT(MACHDEP_OBJS)
|
||||||
|
|
||||||
# checks for library functions
|
# checks for library functions
|
||||||
AC_CHECK_FUNCS(alarm bind_textdomain_codeset chown clock confstr ctermid \
|
AC_CHECK_FUNCS(alarm bind_textdomain_codeset chflags chown clock confstr \
|
||||||
execv fork fpathconf ftime ftruncate \
|
ctermid execv fork fpathconf ftime ftruncate \
|
||||||
gai_strerror getgroups getlogin getloadavg getpeername getpgid getpid \
|
gai_strerror getgroups getlogin getloadavg getpeername getpgid getpid \
|
||||||
getpriority getpwent getspnam getspent getsid getwd \
|
getpriority getpwent getspnam getspent getsid getwd \
|
||||||
kill killpg lchown lstat mkfifo mknod mktime \
|
kill killpg lchflags lchown lstat mkfifo mknod mktime \
|
||||||
mremap nice pathconf pause plock poll pthread_init \
|
mremap nice pathconf pause plock poll pthread_init \
|
||||||
putenv readlink realpath \
|
putenv readlink realpath \
|
||||||
select setegid seteuid setgid \
|
select setegid seteuid setgid \
|
||||||
|
|
|
@ -67,6 +67,9 @@
|
||||||
/* Define this if you have the type _Bool. */
|
/* Define this if you have the type _Bool. */
|
||||||
#undef HAVE_C99_BOOL
|
#undef HAVE_C99_BOOL
|
||||||
|
|
||||||
|
/* Define to 1 if you have the `chflags' function. */
|
||||||
|
#undef HAVE_CHFLAGS
|
||||||
|
|
||||||
/* Define to 1 if you have the `chown' function. */
|
/* Define to 1 if you have the `chown' function. */
|
||||||
#undef HAVE_CHOWN
|
#undef HAVE_CHOWN
|
||||||
|
|
||||||
|
@ -290,6 +293,9 @@
|
||||||
Solaris and Linux, the necessary defines are already defined.) */
|
Solaris and Linux, the necessary defines are already defined.) */
|
||||||
#undef HAVE_LARGEFILE_SUPPORT
|
#undef HAVE_LARGEFILE_SUPPORT
|
||||||
|
|
||||||
|
/* Define to 1 if you have the `lchflags' function. */
|
||||||
|
#undef HAVE_LCHFLAGS
|
||||||
|
|
||||||
/* Define to 1 if you have the `lchown' function. */
|
/* Define to 1 if you have the `lchown' function. */
|
||||||
#undef HAVE_LCHOWN
|
#undef HAVE_LCHOWN
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue