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

Skip to content

Commit 75959cf

Browse files
committed
Issue #15747: skip chflags UF_IMMUTABLE tests if EOPNOTSUPP is raised.
This is necessary for ZFS systems, which don't support UF_IMMUTABLE. (Note: this commit is a manual merge of 78699:019a2390b014 as both _test_chflags_regular_file and test_lchflags_symlink differ between 3.2 and default.)
1 parent dda5edc commit 75959cf

2 files changed

Lines changed: 24 additions & 3 deletions

File tree

Lib/test/test_posix.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,17 @@ def test_utime(self):
534534
def _test_chflags_regular_file(self, chflags_func, target_file, **kwargs):
535535
st = os.stat(target_file)
536536
self.assertTrue(hasattr(st, 'st_flags'))
537-
chflags_func(target_file, st.st_flags | stat.UF_IMMUTABLE, **kwargs)
537+
538+
# ZFS returns EOPNOTSUPP when attempting to set flag UF_IMMUTABLE.
539+
flags = st.st_flags | stat.UF_IMMUTABLE
540+
try:
541+
chflags_func(target_file, flags, **kwargs)
542+
except OSError as err:
543+
if err.errno != errno.EOPNOTSUPP:
544+
raise
545+
msg = 'chflag UF_IMMUTABLE not supported by underlying fs'
546+
self.skipTest(msg)
547+
538548
try:
539549
new_st = os.stat(target_file)
540550
self.assertEqual(st.st_flags | stat.UF_IMMUTABLE, new_st.st_flags)
@@ -568,8 +578,15 @@ def chflags_nofollow(path, flags):
568578
return posix.chflags(path, flags, follow_symlinks=False)
569579

570580
for fn in (posix.lchflags, chflags_nofollow):
571-
fn(_DUMMY_SYMLINK,
572-
dummy_symlink_st.st_flags | stat.UF_IMMUTABLE)
581+
# ZFS returns EOPNOTSUPP when attempting to set flag UF_IMMUTABLE.
582+
flags = dummy_symlink_st.st_flags | stat.UF_IMMUTABLE
583+
try:
584+
fn(_DUMMY_SYMLINK, flags)
585+
except OSError as err:
586+
if err.errno != errno.EOPNOTSUPP:
587+
raise
588+
msg = 'chflag UF_IMMUTABLE not supported by underlying fs'
589+
self.skipTest(msg)
573590
try:
574591
new_testfn_st = os.stat(support.TESTFN)
575592
new_dummy_symlink_st = os.lstat(_DUMMY_SYMLINK)

Misc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ Documentation
8686
Tests
8787
-----
8888

89+
- Issue #15747: ZFS always returns EOPNOTSUPP when attempting to set the
90+
UF_IMMUTABLE flag (via either chflags or lchflags); refactor affected
91+
tests in test_posix.py to account for this.
92+
8993
- Issue #15285: Refactor the approach for testing connect timeouts using
9094
two external hosts that have been configured specifically for this type
9195
of test.

0 commit comments

Comments
 (0)