When running tests, make the directory tree read-only
authorThomas Leonard <talex5@gmail.com>
Sat, 9 Jun 2012 13:44:35 +0000 (9 14:44 +0100)
committerThomas Leonard <talex5@gmail.com>
Sat, 9 Jun 2012 13:44:35 +0000 (9 14:44 +0100)
Checks that tests will still work from the read-only 0install cache.

release.py
support.py

index e38f6c8..865cc46 100644 (file)
@@ -4,6 +4,7 @@
 import os, sys, subprocess, shutil, tempfile
 from zeroinstall import SafeException
 from zeroinstall.injector import reader, model, qdom
+from zeroinstall.support import ro_rmtree
 from logging import info, warn
 
 import support, compile
@@ -470,6 +471,9 @@ def do_release(local_iface, options):
                if status.src_tests_passed:
                        print "Unit-tests already passed - not running again"
                else:
+                       # Make directories read-only (checks tests don't write)
+                       support.make_readonly_recursive(archive_name)
+
                        run_unit_tests(extracted_iface_path)
                        status.src_tests_passed = True
                        status.save()
@@ -478,7 +482,7 @@ def do_release(local_iface, options):
                fail_candidate(archive_file)
                raise
        # Unpack it again in case the unit-tests changed anything
-       shutil.rmtree(archive_name)
+       ro_rmtree(archive_name)
        support.unpack_tarball(archive_file)
 
        # Generate feed for source
index 6537188..bb6e4e2 100644 (file)
@@ -225,3 +225,10 @@ def relative_path(ancestor, dst):
 
 assert relative_path('/foo', '/foo') == 'foo'
 assert relative_path('/foo', '/foo/bar') == 'foo/bar'
+
+def make_readonly_recursive(path):
+       for root, dirs, files in os.walk(path):
+               for d in dirs + files:
+                       full = os.path.join(root, d)
+                       mode = os.stat(full).st_mode
+                       os.chmod(full, mode & 0o555)