@@ -373,6 +373,38 @@ def create_contents(self, paths, filename):
373373 with open (fn , 'wb' ) as f :
374374 f .write (b'Still here?' )
375375
376+ def test_install_scripts_mtime (self ):
377+ """
378+ Test that install_scripts does not preserve mtime when copying scripts.
379+ Using mtime serves as a proxy to verify that shutil.copy2 (and thus
380+ SELinux bin_t contexts) is not being used during script installation.
381+ """
382+ import time
383+ from unittest .mock import patch
384+
385+ builder = venv .EnvBuilder ()
386+ builder .create (self .env_dir )
387+ context = builder .ensure_directories (self .env_dir )
388+
389+ with tempfile .TemporaryDirectory () as script_dir :
390+ common_dir = os .path .join (script_dir , 'common' )
391+ os .mkdir (common_dir )
392+ script_path = os .path .join (common_dir , 'test_script.sh' )
393+
394+ with open (script_path , 'wb' ) as f :
395+ f .write (b'echo Hello' )
396+
397+ past_time = time .time () - 10_000_000
398+ os .utime (script_path , (past_time , past_time ))
399+
400+ builder .install_scripts (context , script_dir )
401+
402+ dst_path = os .path .join (context .bin_path , 'test_script.sh' )
403+ self .assertTrue (os .path .exists (dst_path ))
404+
405+ new_mtime = os .path .getmtime (dst_path )
406+ self .assertGreater (new_mtime , past_time + 1000 )
407+
376408 def test_overwrite_existing (self ):
377409 """
378410 Test creating environment in an existing directory.
0 commit comments