]> granicus.if.org Git - python/commitdiff
Issue #8746: Correct faulty configure checks so that os.chflags() and
authorNed Deily <nad@acm.org>
Tue, 28 Jun 2011 06:41:53 +0000 (23:41 -0700)
committerNed Deily <nad@acm.org>
Tue, 28 Jun 2011 06:41:53 +0000 (23:41 -0700)
os.lchflags() are once again built on systems that support these
functions (*BSD and OS X).  Also add new stat file flags for OS X
(UF_HIDDEN and UF_COMPRESSED).  Also add additional tests for
os.chflags() and os.lchflags(). (Tests by Garrett Cooper)

Doc/library/os.rst
Doc/library/stat.rst
Lib/stat.py
Lib/test/test_posix.py
Misc/ACKS
Misc/NEWS
configure
configure.in
pyconfig.h.in

index 7915b2237b6609aecd32ef51335314dc6dcbe339..d70d45a050331d267a061a1e61d65f6188843096 100644 (file)
@@ -1014,6 +1014,8 @@ Files and Directories
    * :data:`stat.UF_APPEND`
    * :data:`stat.UF_OPAQUE`
    * :data:`stat.UF_NOUNLINK`
+   * :data:`stat.UF_COMPRESSED`
+   * :data:`stat.UF_HIDDEN`
    * :data:`stat.SF_ARCHIVED`
    * :data:`stat.SF_IMMUTABLE`
    * :data:`stat.SF_APPEND`
index f11d21f46eb4d661f77d4beae8dcfea227ad6388..c9c399e30e98ca435d6e336ee086588f925d8769 100644 (file)
@@ -304,13 +304,21 @@ The following flags can be used in the *flags* argument of :func:`os.chflags`:
 
    The file may only be appended to.
 
+.. data:: UF_OPAQUE
+
+   The directory is opaque when viewed through a union stack.
+
 .. data:: UF_NOUNLINK
 
    The file may not be renamed or deleted.
 
-.. data:: UF_OPAQUE
+.. data:: UF_COMPRESSED
 
-   The directory is opaque when viewed through a union stack.
+   The file is stored compressed (Mac OS X 10.6+).
+
+.. data:: UF_HIDDEN
+
+   The file should not be displayed in a GUI (Mac OS X 10.5+).
 
 .. data:: SF_ARCHIVED
 
index 4a9d30c16c2ead62ec66ab3d4127b8d89a1e283a..abed5c9e0f57a118ee58aef158cf3c455d9821ec 100644 (file)
@@ -87,6 +87,8 @@ UF_IMMUTABLE = 0x00000002
 UF_APPEND    = 0x00000004
 UF_OPAQUE    = 0x00000008
 UF_NOUNLINK  = 0x00000010
+UF_COMPRESSED = 0x00000020  # OS X: file is hfs-compressed
+UF_HIDDEN    = 0x00008000   # OS X: file should not be displayed
 SF_ARCHIVED  = 0x00010000
 SF_IMMUTABLE = 0x00020000
 SF_APPEND    = 0x00040000
index a5db21eefbd7de7396ecc9ce377a4f7e6e049493..3b9bc205a0660dcd5dfbf8427ef1e55ef21df817 100644 (file)
@@ -11,10 +11,12 @@ import time
 import os
 import pwd
 import shutil
+import stat
 import sys
 import unittest
 import warnings
 
+_DUMMY_SYMLINK = '%s/dummy-symlink' % os.getenv('TMPDIR', '/tmp')
 
 warnings.filterwarnings('ignore', '.* potential security risk .*',
                         RuntimeWarning)
@@ -25,9 +27,11 @@ class PosixTester(unittest.TestCase):
         # create empty file
         fp = open(test_support.TESTFN, 'w+')
         fp.close()
+        self.teardown_files = [ test_support.TESTFN ]
 
     def tearDown(self):
-        os.unlink(test_support.TESTFN)
+        for teardown_file in self.teardown_files:
+            os.unlink(teardown_file)
 
     def testNoArgFunctions(self):
         # test posix functions which take no arguments and have
@@ -258,7 +262,7 @@ class PosixTester(unittest.TestCase):
     def test_lchown(self):
         os.unlink(test_support.TESTFN)
         # create a symlink
-        os.symlink('/tmp/dummy-symlink-target', test_support.TESTFN)
+        os.symlink(_DUMMY_SYMLINK, test_support.TESTFN)
         self._test_all_chown_common(posix.lchown, test_support.TESTFN)
 
     def test_chdir(self):
@@ -315,17 +319,49 @@ class PosixTester(unittest.TestCase):
             posix.utime(test_support.TESTFN, (int(now), int(now)))
             posix.utime(test_support.TESTFN, (now, now))
 
+    def _test_chflags_regular_file(self, chflags_func, target_file):
+        st = os.stat(target_file)
+        self.assertTrue(hasattr(st, 'st_flags'))
+        chflags_func(target_file, st.st_flags | stat.UF_IMMUTABLE)
+        try:
+            new_st = os.stat(target_file)
+            self.assertEqual(st.st_flags | stat.UF_IMMUTABLE, new_st.st_flags)
+            try:
+                fd = open(target_file, 'w+')
+            except IOError as e:
+                self.assertEqual(e.errno, errno.EPERM)
+        finally:
+            posix.chflags(target_file, st.st_flags)
+
+    @unittest.skipUnless(hasattr(posix, 'chflags'), 'test needs os.chflags()')
     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)
+        self._test_chflags_regular_file(posix.chflags, test_support.TESTFN)
+
+    @unittest.skipUnless(hasattr(posix, 'lchflags'), 'test needs os.lchflags()')
+    def test_lchflags_regular_file(self):
+        self._test_chflags_regular_file(posix.lchflags, test_support.TESTFN)
+
+    @unittest.skipUnless(hasattr(posix, 'lchflags'), 'test needs os.lchflags()')
+    def test_lchflags_symlink(self):
+        testfn_st = os.stat(test_support.TESTFN)
+
+        self.assertTrue(hasattr(testfn_st, 'st_flags'))
+
+        os.symlink(test_support.TESTFN, _DUMMY_SYMLINK)
+        self.teardown_files.append(_DUMMY_SYMLINK)
+        dummy_symlink_st = os.lstat(_DUMMY_SYMLINK)
+
+        posix.lchflags(_DUMMY_SYMLINK,
+                       dummy_symlink_st.st_flags | stat.UF_IMMUTABLE)
+        try:
+            new_testfn_st = os.stat(test_support.TESTFN)
+            new_dummy_symlink_st = os.lstat(_DUMMY_SYMLINK)
+
+            self.assertEqual(testfn_st.st_flags, new_testfn_st.st_flags)
+            self.assertEqual(dummy_symlink_st.st_flags | stat.UF_IMMUTABLE,
+                             new_dummy_symlink_st.st_flags)
+        finally:
+            posix.lchflags(_DUMMY_SYMLINK, dummy_symlink_st.st_flags)
 
     def test_getcwd_long_pathnames(self):
         if hasattr(posix, 'getcwd'):
index 4cdf5f4217d34fb981a09411a089aa67c8c08de3..709ded3b73555136bcbcc14cfb2be154317f4bb7 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -162,6 +162,7 @@ Geremy Condra
 Juan José Conti
 Matt Conway
 David M. Cooke
+Garrett Cooper
 Greg Copeland
 Aldo Cortesi
 David Costanzo
index ac383e0281d0a8ddbd7447334956103ca6067bc5..b1742b05a3f2422740dd451956b98625abdcf1ab 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -53,9 +53,20 @@ Library
   constructor has failed, e.g. because of an undeclared keyword argument. Patch
   written by Oleg Oshmyan.
 
+Build
+-----
+
+- Issue #8746: Correct faulty configure checks so that os.chflags() and
+  os.lchflags() are once again built on systems that support these
+  functions (*BSD and OS X).  Also add new stat file flags for OS X
+  (UF_HIDDEN and UF_COMPRESSED).
+
 Tests
 -----
 
+- Issue #8746: Add additional tests for os.chflags() and os.lchflags().
+  Patch by Garrett Cooper.
+
 - Issue #10736: Fix test_ttk test_widgets failures with Cocoa Tk 8.5.9
   on Mac OS X.  (Patch by Ronald Oussoren)
 
index 29ce00c1af553fc23b21bbbb109df116c35873b8..4a60b10b2e1294e12e06336dffed820df9e3923b 100755 (executable)
--- a/configure
+++ b/configure
@@ -10073,7 +10073,7 @@ else
 else
   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
-[
+
 #include <sys/stat.h>
 #include <unistd.h>
 int main(int argc, char*argv[])
@@ -10082,7 +10082,7 @@ int main(int argc, char*argv[])
     return 1;
   return 0;
 }
-]
+
 _ACEOF
 if ac_fn_c_try_run "$LINENO"; then :
   ac_cv_have_chflags=yes
@@ -10122,7 +10122,7 @@ else
 else
   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
-[
+
 #include <sys/stat.h>
 #include <unistd.h>
 int main(int argc, char*argv[])
@@ -10131,7 +10131,7 @@ int main(int argc, char*argv[])
     return 1;
   return 0;
 }
-]
+
 _ACEOF
 if ac_fn_c_try_run "$LINENO"; then :
   ac_cv_have_lchflags=yes
index ea106b525f33ee84d79540a2cba7dfecc6ab15ea..9749e790cc26c1ecfa8649fce716a180796b9edd 100644 (file)
@@ -2839,7 +2839,7 @@ AC_CHECK_LIB(c, inet_aton, [$ac_cv_prog_TRUE],
 # On Tru64, chflags seems to be present, but calling it will
 # exit Python
 AC_CACHE_CHECK([for chflags], [ac_cv_have_chflags], [dnl
-AC_RUN_IFELSE([AC_LANG_SOURCE([[[
+AC_RUN_IFELSE([AC_LANG_SOURCE([[
 #include <sys/stat.h>
 #include <unistd.h>
 int main(int argc, char*argv[])
@@ -2848,7 +2848,7 @@ int main(int argc, char*argv[])
     return 1;
   return 0;
 }
-]]])],
+]])],
 [ac_cv_have_chflags=yes],
 [ac_cv_have_chflags=no],
 [ac_cv_have_chflags=cross])
@@ -2857,11 +2857,11 @@ if test "$ac_cv_have_chflags" = cross ; then
   AC_CHECK_FUNC([chflags], [ac_cv_have_chflags="yes"], [ac_cv_have_chflags="no"])
 fi
 if test "$ac_cv_have_chflags" = yes ; then
-  AC_DEFINE(HAVE_CHFLAGS, 1, [Define to 1 if you have the `chflags' function.])
+  AC_DEFINE(HAVE_CHFLAGS, 1, [Define to 1 if you have the 'chflags' function.])
 fi
 
 AC_CACHE_CHECK([for lchflags], [ac_cv_have_lchflags], [dnl
-AC_RUN_IFELSE([AC_LANG_SOURCE([[[
+AC_RUN_IFELSE([AC_LANG_SOURCE([[
 #include <sys/stat.h>
 #include <unistd.h>
 int main(int argc, char*argv[])
@@ -2870,13 +2870,13 @@ int main(int argc, char*argv[])
     return 1;
   return 0;
 }
-]]])],[ac_cv_have_lchflags=yes],[ac_cv_have_lchflags=no],[ac_cv_have_lchflags=cross])
+]])],[ac_cv_have_lchflags=yes],[ac_cv_have_lchflags=no],[ac_cv_have_lchflags=cross])
 ])
 if test "$ac_cv_have_lchflags" = cross ; then
   AC_CHECK_FUNC([lchflags], [ac_cv_have_lchflags="yes"], [ac_cv_have_lchflags="no"])
 fi
 if test "$ac_cv_have_lchflags" = yes ; then
-  AC_DEFINE(HAVE_LCHFLAGS, 1, [Define to 1 if you have the `lchflags' function.])
+  AC_DEFINE(HAVE_LCHFLAGS, 1, [Define to 1 if you have the 'lchflags' function.])
 fi
 
 dnl Check if system zlib has *Copy() functions
index 65ad7acac33e7ce020fa17ff7e1ba6b7e1b6af18..9d340f6e0afeae0565cd9faf229a01330225f43c 100644 (file)
 /* Define this if you have the type _Bool. */
 #undef HAVE_C99_BOOL
 
-/* Define to 1 if you have the `chflags' function. */
+/* Define to 1 if you have the 'chflags' function. */
 #undef HAVE_CHFLAGS
 
 /* Define to 1 if you have the `chown' function. */
    Solaris and Linux, the necessary defines are already defined.) */
 #undef HAVE_LARGEFILE_SUPPORT
 
-/* Define to 1 if you have the `lchflags' function. */
+/* Define to 1 if you have the 'lchflags' function. */
 #undef HAVE_LCHFLAGS
 
 /* Define to 1 if you have the `lchmod' function. */
 /* This must be defined on some systems to enable large file support. */
 #undef _LARGEFILE_SOURCE
 
+/* This must be defined on AIX systems to enable large file support. */
+#undef _LARGE_FILES
+
 /* Define to 1 if on MINIX. */
 #undef _MINIX