[meld] Re-add writeable permission before deleting temp files on Windows



commit 8afa3de37cdca01967cf7e8e548fec0e852bceaf
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Sun Mar 31 14:22:48 2013 +1000

    Re-add writeable permission before deleting temp files on Windows
    
    Windows refuses to delete non-writeable ('write protected') files, so
    we re-add removed write permissions before deleting when running on
    Windows.

 meld/vcview.py |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
---
diff --git a/meld/vcview.py b/meld/vcview.py
index 54630fb..89cf9ae 100644
--- a/meld/vcview.py
+++ b/meld/vcview.py
@@ -22,6 +22,7 @@ import atexit
 import tempfile
 import shutil
 import os
+import stat
 import sys
 from gettext import gettext as _
 
@@ -59,6 +60,9 @@ def cleanup_temp():
         try:
             assert os.path.exists(f) and os.path.isabs(f) and \
                    os.path.dirname(f) == temp_location
+            # Windows throws permissions errors if we remove read-only files
+            if os.name == "nt":
+                os.chmod(f, stat.S_IWRITE)
             os.remove(f)
         except:
             except_str = "{0[0]}: \"{0[1]}\"".format(sys.exc_info())


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]