]> scripts.mit.edu Git - wizard.git/commitdiff
Check if all files are writable before upgrading.
authorEdward Z. Yang <ezyang@mit.edu>
Sun, 7 Feb 2010 23:49:30 +0000 (18:49 -0500)
committerEdward Z. Yang <ezyang@mit.edu>
Tue, 9 Mar 2010 02:40:54 +0000 (21:40 -0500)
Signed-off-by: Edward Z. Yang <ezyang@mit.edu>
wizard/command/upgrade.py
wizard/util.py

index c0647b6eb3b66675067774a3b99d0ba0c2fd5e7d..30dab29ed1a454f23bac05a694688ff08b03ee26 100644 (file)
@@ -154,6 +154,7 @@ class Upgrade(object):
             self.prod = deploy.ProductionCopy(".")
             self.prod.verify()
             self.repo = self.prod.application.repository(options.srv_path)
+            util.assert_all_writable()
             # XXX: put this in Application
             self.version = shell.eval("git", "--git-dir="+self.repo, "describe", "--tags", "master")
             self.preflightBlacklist()
index 1c884035af4e04562488301e75d164fa6cd9e848..0335bc6ef48bb17ec66ad0102a99161c965b6e64 100644 (file)
@@ -372,6 +372,16 @@ def mixed_newlines(filename):
     f.close() # just to be safe
     return ret
 
+def assert_all_writable(dir="."):
+    """Recursively checks if all files and directories in a directory are
+    writable.  Raises :exc:`PermissionsError` if this is not true."""
+    for dirpath, dirname, filenames in os.walk(dir):
+        if not os.access(dirpath, os.W_OK):
+            raise PermissionsError
+        for filename in filenames:
+            if not os.access(os.path.join(dirpath, filename), os.W_OK):
+                raise PermissionsError
+
 class NoOperatorInfo(wizard.Error):
     """No information could be found about the operator from Kerberos."""
     pass