Skip to content

Commit

Permalink
test_copy_file_xattr
Browse files Browse the repository at this point in the history
  • Loading branch information
boegel committed Sep 18, 2024
1 parent f7035e9 commit 6338a50
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions test/framework/filetools.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
from easybuild.tools.config import IGNORE, ERROR, build_option, update_build_option
from easybuild.tools.multidiff import multidiff
from easybuild.tools.py2vs3 import StringIO, std_urllib
from easybuild.tools.run import run_cmd


class FileToolsTest(EnhancedTestCase):
Expand Down Expand Up @@ -1912,6 +1913,29 @@ def test_copy_file(self):
# However, if we add 'force_in_dry_run=True' it should throw an exception
self.assertErrorRegex(EasyBuildError, "Could not copy *", ft.copy_file, src, target, force_in_dry_run=True)

def test_copy_file_xattr(self):
"""Test copying a file with extended attributes using copy_file."""
# test copying a read-only files with extended attributes set
# first, create a special file with extended attributes
special_file = os.path.join(self.test_prefix, 'special.txt')
ft.write_file(special_file, 'special')
# make read-only, and set extended attributes
ft.adjust_permissions(special_file, stat.S_IWUSR | stat.S_IWGRP | stat.S_IWOTH, add=False)
attr = ft.which('attr')
xattr = ft.which('xattr')
# try to attr (Linux) or xattr (macOS) to set extended attributes foo=bar
xattr_set = False
if attr:
cmd = "attr -s foo -V bar %s" % special_file
xattr_set = ec == 0
elif xattr:
cmd = "xattr -w foo bar %s" % special_file

(_, ec) = run_cmd(cmd, simple=False, log_all=False, log_ok=False)
if ec == 0:
target = os.path.join(self.test_prefix, 'copy.txt')
ft.copy_file(special_file, target)

def test_copy_files(self):
"""Test copy_files function."""
test_ecs = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'easyconfigs', 'test_ecs')
Expand Down

0 comments on commit 6338a50

Please sign in to comment.