(original) (raw)

changeset: 71032:9da64c0bdc33 parent: 71029:b7c61000ceec parent: 71031:529e26aa4fa3 user: Ned Deily nad@acm.org date: Tue Jun 28 00:13:01 2011 -0700 files: Doc/library/os.rst Lib/test/test_posix.py Misc/ACKS Misc/NEWS configure configure.in pyconfig.h.in description: 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). Also add additional tests for os.chflags() and os.lchflags(). (Tests by Garrett Cooper) diff -r b7c61000ceec -r 9da64c0bdc33 Doc/library/os.rst --- a/Doc/library/os.rst Mon Jun 27 23🔞45 2011 -0700 +++ b/Doc/library/os.rst Tue Jun 28 00:13:01 2011 -0700 @@ -1465,6 +1465,8 @@ * :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` diff -r b7c61000ceec -r 9da64c0bdc33 Doc/library/stat.rst --- a/Doc/library/stat.rst Mon Jun 27 23🔞45 2011 -0700 +++ b/Doc/library/stat.rst Tue Jun 28 00:13:01 2011 -0700 @@ -307,13 +307,21 @@ 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 file is stored compressed (Mac OS X 10.6+). - The directory is opaque when viewed through a union stack. +.. data:: UF_HIDDEN + + The file should not be displayed in a GUI (Mac OS X 10.5+). .. data:: SF_ARCHIVED diff -r b7c61000ceec -r 9da64c0bdc33 Lib/stat.py --- a/Lib/stat.py Mon Jun 27 23🔞45 2011 -0700 +++ b/Lib/stat.py Tue Jun 28 00:13:01 2011 -0700 @@ -87,6 +87,8 @@ 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 diff -r b7c61000ceec -r 9da64c0bdc33 Lib/test/test_posix.py --- a/Lib/test/test_posix.py Mon Jun 27 23🔞45 2011 -0700 +++ b/Lib/test/test_posix.py Tue Jun 28 00:13:01 2011 -0700 @@ -16,6 +16,7 @@ import unittest import warnings +_DUMMY_SYMLINK = '%s/dummy-symlink' % os.getenv('TMPDIR', '/tmp') class PosixTester(unittest.TestCase): @@ -23,13 +24,15 @@ # create empty file fp = open(support.TESTFN, 'w+') fp.close() + self.teardown_files = [ support.TESTFN ] self._warnings_manager = support.check_warnings() self._warnings_manager.__enter__() warnings.filterwarnings('ignore', '.* potential security risk .*', RuntimeWarning) def tearDown(self): - support.unlink(support.TESTFN) + for teardown_file in self.teardown_files: + support.unlink(teardown_file) self._warnings_manager.__exit__(None, None, None) def testNoArgFunctions(self): @@ -426,7 +429,7 @@ def test_lchown(self): os.unlink(support.TESTFN) # create a symlink - os.symlink('/tmp/dummy-symlink-target', support.TESTFN) + os.symlink(_DUMMY_SYMLINK, support.TESTFN) self._test_all_chown_common(posix.lchown, support.TESTFN) def test_chdir(self): @@ -511,17 +514,49 @@ posix.utime(support.TESTFN, (int(now), int(now))) posix.utime(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(support.TESTFN) - if hasattr(st, 'st_flags'): - posix.chflags(support.TESTFN, st.st_flags) + self._test_chflags_regular_file(posix.chflags, support.TESTFN) + + @unittest.skipUnless(hasattr(posix, 'lchflags'), 'test needs os.lchflags()') + def test_lchflags_regular_file(self): + self._test_chflags_regular_file(posix.lchflags, support.TESTFN) - def test_lchflags(self): - if hasattr(posix, 'lchflags'): - st = os.stat(support.TESTFN) - if hasattr(st, 'st_flags'): - posix.lchflags(support.TESTFN, st.st_flags) + @unittest.skipUnless(hasattr(posix, 'lchflags'), 'test needs os.lchflags()') + def test_lchflags_symlink(self): + testfn_st = os.stat(support.TESTFN) + + self.assertTrue(hasattr(testfn_st, 'st_flags')) + + os.symlink(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(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_environ(self): if os.name == "nt": diff -r b7c61000ceec -r 9da64c0bdc33 Misc/ACKS --- a/Misc/ACKS Mon Jun 27 23🔞45 2011 -0700 +++ b/Misc/ACKS Tue Jun 28 00:13:01 2011 -0700 @@ -191,6 +191,7 @@ Matt Conway David M. Cooke Jason R. Coombs +Garrett Cooper Greg Copeland Aldo Cortesi David Costanzo diff -r b7c61000ceec -r 9da64c0bdc33 Misc/NEWS --- a/Misc/NEWS Mon Jun 27 23🔞45 2011 -0700 +++ b/Misc/NEWS Tue Jun 28 00:13:01 2011 -0700 @@ -857,6 +857,11 @@ 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). + - Issue #10645: Installing Python does no longer create a Python-X.Y.Z-pyX.Y.egg-info file in the lib-dynload directory. @@ -908,6 +913,9 @@ 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 2.8 + on Mac OS X. (Patch by Ronald Oussoren) diff -r b7c61000ceec -r 9da64c0bdc33 configure --- a/configure Mon Jun 27 23🔞45 2011 -0700 +++ b/configure Tue Jun 28 00:13:01 2011 -0700 @@ -9912,7 +9912,7 @@ else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ -[ + #include #include int main(int argc, char*argv[]) @@ -9921,7 +9921,7 @@ return 1; return 0; } -] + _ACEOF if ac_fn_c_try_run "$LINENO"; then : ac_cv_have_chflags=yes @@ -9961,7 +9961,7 @@ else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ -[ + #include #include int main(int argc, char*argv[]) @@ -9970,7 +9970,7 @@ return 1; return 0; } -] + _ACEOF if ac_fn_c_try_run "$LINENO"; then : ac_cv_have_lchflags=yes diff -r b7c61000ceec -r 9da64c0bdc33 configure.in --- a/configure.in Mon Jun 27 23🔞45 2011 -0700 +++ b/configure.in Tue Jun 28 00:13:01 2011 -0700 @@ -2675,7 +2675,7 @@ # 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 #include int main(int argc, char*argv[]) @@ -2684,7 +2684,7 @@ return 1; return 0; } -]]])], +]])], [ac_cv_have_chflags=yes], [ac_cv_have_chflags=no], [ac_cv_have_chflags=cross]) @@ -2693,11 +2693,11 @@ 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 #include int main(int argc, char*argv[]) @@ -2706,13 +2706,13 @@ 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 diff -r b7c61000ceec -r 9da64c0bdc33 pyconfig.h.in --- a/pyconfig.h.in Mon Jun 27 23🔞45 2011 -0700 +++ b/pyconfig.h.in Tue Jun 28 00:13:01 2011 -0700 @@ -101,7 +101,7 @@ /* 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. */ @@ -428,7 +428,7 @@ 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. *//nad@acm.org