[PATCH resend] util: make atomictempfile keep win32-specific file attrs

Yuya Nishihara yuya at tcha.org
Wed May 26 11:57:22 CDT 2010


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1274372380 -32400
# Node ID 69868c45734e340fc79e9e8e95a85f2c5e7b09a5
# Parent  868755d58e4f9bc6636337786a71afef7f0a96ea
util: make atomictempfile keep win32-specific file attrs

Main intention of this change is to preserve "hidden" attribute.

It copies file attributes at end, not first, because some attributes are
troublesome when editing. For example, hidden files are not truncatable
on NTFS, thus we cannot open('hidden-file', 'w') if set "hidden" before
opening.

diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -553,6 +553,10 @@ def hidewindow():
     """
     pass
 
+def copyextrafileattrs(src, dest):
+    """copy platform-specific file attributes"""
+    pass
+
 if os.name == 'nt':
     from windows import *
 else:
@@ -785,6 +789,8 @@ class atomictempfile(object):
     def rename(self):
         if not self._fp.closed:
             self._fp.close()
+            # set attrs at end because they are troublesome on editing
+            copyextrafileattrs(localpath(self.__name), self.temp)
             rename(self.temp, localpath(self.__name))
 
     def __del__(self):
diff --git a/mercurial/win32.py b/mercurial/win32.py
--- a/mercurial/win32.py
+++ b/mercurial/win32.py
@@ -202,3 +202,10 @@ def termwidth_():
             screenbuf.Detach()
     except pywintypes.error:
         return 79
+
+def copyextrafileattrs(src, dest):
+    """copy windows-specific file attributes like hidden flag"""
+    try:
+        win32api.SetFileAttributes(dest, win32api.GetFileAttributes(src))
+    except pywintypes.error:
+        pass


More information about the Mercurial-devel mailing list