Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3eb67d5

Browse files
committed
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)
1 parent 11f00f3 commit 3eb67d5

9 files changed

Lines changed: 85 additions & 26 deletions

File tree

Doc/library/os.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -989,6 +989,8 @@ Files and Directories
989989
* :data:`stat.UF_APPEND`
990990
* :data:`stat.UF_OPAQUE`
991991
* :data:`stat.UF_NOUNLINK`
992+
* :data:`stat.UF_COMPRESSED`
993+
* :data:`stat.UF_HIDDEN`
992994
* :data:`stat.SF_ARCHIVED`
993995
* :data:`stat.SF_IMMUTABLE`
994996
* :data:`stat.SF_APPEND`

Doc/library/stat.rst

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,13 +307,21 @@ The following flags can be used in the *flags* argument of :func:`os.chflags`:
307307

308308
The file may only be appended to.
309309

310+
.. data:: UF_OPAQUE
311+
312+
The directory is opaque when viewed through a union stack.
313+
310314
.. data:: UF_NOUNLINK
311315

312316
The file may not be renamed or deleted.
313317

314-
.. data:: UF_OPAQUE
318+
.. data:: UF_COMPRESSED
315319

316-
The directory is opaque when viewed through a union stack.
320+
The file is stored compressed (Mac OS X 10.6+).
321+
322+
.. data:: UF_HIDDEN
323+
324+
The file should not be displayed in a GUI (Mac OS X 10.5+).
317325

318326
.. data:: SF_ARCHIVED
319327

Lib/stat.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ def S_ISSOCK(mode):
8787
UF_APPEND = 0x00000004
8888
UF_OPAQUE = 0x00000008
8989
UF_NOUNLINK = 0x00000010
90+
UF_COMPRESSED = 0x00000020 # OS X: file is hfs-compressed
91+
UF_HIDDEN = 0x00008000 # OS X: file should not be displayed
9092
SF_ARCHIVED = 0x00010000
9193
SF_IMMUTABLE = 0x00020000
9294
SF_APPEND = 0x00040000

Lib/test/test_posix.py

Lines changed: 47 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,23 @@
1515
import unittest
1616
import warnings
1717

18+
_DUMMY_SYMLINK = '%s/dummy-symlink' % os.getenv('TMPDIR', '/tmp')
1819

1920
class PosixTester(unittest.TestCase):
2021

2122
def setUp(self):
2223
# create empty file
2324
fp = open(support.TESTFN, 'w+')
2425
fp.close()
26+
self.teardown_files = [ support.TESTFN ]
2527
self._warnings_manager = support.check_warnings()
2628
self._warnings_manager.__enter__()
2729
warnings.filterwarnings('ignore', '.* potential security risk .*',
2830
RuntimeWarning)
2931

3032
def tearDown(self):
31-
support.unlink(support.TESTFN)
33+
for teardown_file in self.teardown_files:
34+
support.unlink(teardown_file)
3235
self._warnings_manager.__exit__(None, None, None)
3336

3437
def testNoArgFunctions(self):
@@ -268,7 +271,7 @@ def test_fchown(self):
268271
def test_lchown(self):
269272
os.unlink(support.TESTFN)
270273
# create a symlink
271-
os.symlink('/tmp/dummy-symlink-target', support.TESTFN)
274+
os.symlink(_DUMMY_SYMLINK, support.TESTFN)
272275
self._test_all_chown_common(posix.lchown, support.TESTFN)
273276

274277
def test_chdir(self):
@@ -315,17 +318,49 @@ def test_utime(self):
315318
posix.utime(support.TESTFN, (int(now), int(now)))
316319
posix.utime(support.TESTFN, (now, now))
317320

321+
def _test_chflags_regular_file(self, chflags_func, target_file):
322+
st = os.stat(target_file)
323+
self.assertTrue(hasattr(st, 'st_flags'))
324+
chflags_func(target_file, st.st_flags | stat.UF_IMMUTABLE)
325+
try:
326+
new_st = os.stat(target_file)
327+
self.assertEqual(st.st_flags | stat.UF_IMMUTABLE, new_st.st_flags)
328+
try:
329+
fd = open(target_file, 'w+')
330+
except IOError as e:
331+
self.assertEqual(e.errno, errno.EPERM)
332+
finally:
333+
posix.chflags(target_file, st.st_flags)
334+
335+
@unittest.skipUnless(hasattr(posix, 'chflags'), 'test needs os.chflags()')
318336
def test_chflags(self):
319-
if hasattr(posix, 'chflags'):
320-
st = os.stat(support.TESTFN)
321-
if hasattr(st, 'st_flags'):
322-
posix.chflags(support.TESTFN, st.st_flags)
323-
324-
def test_lchflags(self):
325-
if hasattr(posix, 'lchflags'):
326-
st = os.stat(support.TESTFN)
327-
if hasattr(st, 'st_flags'):
328-
posix.lchflags(support.TESTFN, st.st_flags)
337+
self._test_chflags_regular_file(posix.chflags, support.TESTFN)
338+
339+
@unittest.skipUnless(hasattr(posix, 'lchflags'), 'test needs os.lchflags()')
340+
def test_lchflags_regular_file(self):
341+
self._test_chflags_regular_file(posix.lchflags, support.TESTFN)
342+
343+
@unittest.skipUnless(hasattr(posix, 'lchflags'), 'test needs os.lchflags()')
344+
def test_lchflags_symlink(self):
345+
testfn_st = os.stat(support.TESTFN)
346+
347+
self.assertTrue(hasattr(testfn_st, 'st_flags'))
348+
349+
os.symlink(support.TESTFN, _DUMMY_SYMLINK)
350+
self.teardown_files.append(_DUMMY_SYMLINK)
351+
dummy_symlink_st = os.lstat(_DUMMY_SYMLINK)
352+
353+
posix.lchflags(_DUMMY_SYMLINK,
354+
dummy_symlink_st.st_flags | stat.UF_IMMUTABLE)
355+
try:
356+
new_testfn_st = os.stat(support.TESTFN)
357+
new_dummy_symlink_st = os.lstat(_DUMMY_SYMLINK)
358+
359+
self.assertEqual(testfn_st.st_flags, new_testfn_st.st_flags)
360+
self.assertEqual(dummy_symlink_st.st_flags | stat.UF_IMMUTABLE,
361+
new_dummy_symlink_st.st_flags)
362+
finally:
363+
posix.lchflags(_DUMMY_SYMLINK, dummy_symlink_st.st_flags)
329364

330365
def test_environ(self):
331366
if os.name == "nt":

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ Juan José Conti
181181
Matt Conway
182182
David M. Cooke
183183
Jason R. Coombs
184+
Garrett Cooper
184185
Greg Copeland
185186
Aldo Cortesi
186187
David Costanzo

Misc/NEWS

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,21 @@ Extension Modules
9999
Build
100100
-----
101101

102+
- Issue #8746: Correct faulty configure checks so that os.chflags() and
103+
os.lchflags() are once again built on systems that support these
104+
functions (*BSD and OS X). Also add new stat file flags for OS X
105+
(UF_HIDDEN and UF_COMPRESSED).
106+
102107
- Issue #11217: For 64-bit/32-bit Mac OS X universal framework builds,
103108
ensure "make install" creates symlinks in --prefix bin for the "-32"
104109
files in the framework bin directory like the installer does.
105110

106111
Tests
107112
-----
108113

114+
- Issue #8746: Add additional tests for os.chflags() and os.lchflags().
115+
Patch by Garrett Cooper.
116+
109117
- Issue #10736: Fix test_ttk test_widgets failures with Cocoa Tk 8.5.9
110118
on Mac OS X. (Patch by Ronald Oussoren)
111119

configure

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9877,7 +9877,7 @@ else
98779877
else
98789878
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
98799879
/* end confdefs.h. */
9880-
[
9880+
98819881
#include <sys/stat.h>
98829882
#include <unistd.h>
98839883
int main(int argc, char*argv[])
@@ -9886,7 +9886,7 @@ int main(int argc, char*argv[])
98869886
return 1;
98879887
return 0;
98889888
}
9889-
]
9889+
98909890
_ACEOF
98919891
if ac_fn_c_try_run "$LINENO"; then :
98929892
ac_cv_have_chflags=yes
@@ -9926,7 +9926,7 @@ else
99269926
else
99279927
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
99289928
/* end confdefs.h. */
9929-
[
9929+
99309930
#include <sys/stat.h>
99319931
#include <unistd.h>
99329932
int main(int argc, char*argv[])
@@ -9935,7 +9935,7 @@ int main(int argc, char*argv[])
99359935
return 1;
99369936
return 0;
99379937
}
9938-
]
9938+
99399939
_ACEOF
99409940
if ac_fn_c_try_run "$LINENO"; then :
99419941
ac_cv_have_lchflags=yes

configure.in

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2689,7 +2689,7 @@ AC_CHECK_LIB(c, inet_aton, [$ac_cv_prog_TRUE],
26892689
# On Tru64, chflags seems to be present, but calling it will
26902690
# exit Python
26912691
AC_CACHE_CHECK([for chflags], [ac_cv_have_chflags], [dnl
2692-
AC_RUN_IFELSE([AC_LANG_SOURCE([[[
2692+
AC_RUN_IFELSE([AC_LANG_SOURCE([[
26932693
#include <sys/stat.h>
26942694
#include <unistd.h>
26952695
int main(int argc, char*argv[])
@@ -2698,7 +2698,7 @@ int main(int argc, char*argv[])
26982698
return 1;
26992699
return 0;
27002700
}
2701-
]]])],
2701+
]])],
27022702
[ac_cv_have_chflags=yes],
27032703
[ac_cv_have_chflags=no],
27042704
[ac_cv_have_chflags=cross])
@@ -2707,11 +2707,11 @@ if test "$ac_cv_have_chflags" = cross ; then
27072707
AC_CHECK_FUNC([chflags], [ac_cv_have_chflags="yes"], [ac_cv_have_chflags="no"])
27082708
fi
27092709
if test "$ac_cv_have_chflags" = yes ; then
2710-
AC_DEFINE(HAVE_CHFLAGS, 1, [Define to 1 if you have the `chflags' function.])
2710+
AC_DEFINE(HAVE_CHFLAGS, 1, [Define to 1 if you have the 'chflags' function.])
27112711
fi
27122712

27132713
AC_CACHE_CHECK([for lchflags], [ac_cv_have_lchflags], [dnl
2714-
AC_RUN_IFELSE([AC_LANG_SOURCE([[[
2714+
AC_RUN_IFELSE([AC_LANG_SOURCE([[
27152715
#include <sys/stat.h>
27162716
#include <unistd.h>
27172717
int main(int argc, char*argv[])
@@ -2720,13 +2720,13 @@ int main(int argc, char*argv[])
27202720
return 1;
27212721
return 0;
27222722
}
2723-
]]])],[ac_cv_have_lchflags=yes],[ac_cv_have_lchflags=no],[ac_cv_have_lchflags=cross])
2723+
]])],[ac_cv_have_lchflags=yes],[ac_cv_have_lchflags=no],[ac_cv_have_lchflags=cross])
27242724
])
27252725
if test "$ac_cv_have_lchflags" = cross ; then
27262726
AC_CHECK_FUNC([lchflags], [ac_cv_have_lchflags="yes"], [ac_cv_have_lchflags="no"])
27272727
fi
27282728
if test "$ac_cv_have_lchflags" = yes ; then
2729-
AC_DEFINE(HAVE_LCHFLAGS, 1, [Define to 1 if you have the `lchflags' function.])
2729+
AC_DEFINE(HAVE_LCHFLAGS, 1, [Define to 1 if you have the 'lchflags' function.])
27302730
fi
27312731

27322732
dnl Check if system zlib has *Copy() functions

pyconfig.h.in

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@
101101
/* Define this if you have the type _Bool. */
102102
#undef HAVE_C99_BOOL
103103

104-
/* Define to 1 if you have the `chflags' function. */
104+
/* Define to 1 if you have the 'chflags' function. */
105105
#undef HAVE_CHFLAGS
106106

107107
/* Define to 1 if you have the `chown' function. */
@@ -395,7 +395,7 @@
395395
Solaris and Linux, the necessary defines are already defined.) */
396396
#undef HAVE_LARGEFILE_SUPPORT
397397

398-
/* Define to 1 if you have the `lchflags' function. */
398+
/* Define to 1 if you have the 'lchflags' function. */
399399
#undef HAVE_LCHFLAGS
400400

401401
/* Define to 1 if you have the `lchmod' function. */
@@ -1152,6 +1152,9 @@
11521152
/* This must be defined on some systems to enable large file support. */
11531153
#undef _LARGEFILE_SOURCE
11541154

1155+
/* This must be defined on AIX systems to enable large file support. */
1156+
#undef _LARGE_FILES
1157+
11551158
/* Define to 1 if on MINIX. */
11561159
#undef _MINIX
11571160

0 commit comments

Comments
 (0)