[PATCH 1 of 1] util.mktempcopy: eliminate pointless lstat / chmod calls on Windows
Adrian Buehlmann
adrian at cadifra.com
Mon Jun 20 09:45:40 UTC 2011
# HG changeset patch
# User Adrian Buehlmann <adrian at cadifra.com>
# Date 1308558845 -7200
# Branch stable
# Node ID e2a259aa747155ded2b960fafc20809a0fbcd16d
# Parent 15faf0e66909286e9ca88f536a160db1d2fc6aac
util.mktempcopy: eliminate pointless lstat / chmod calls on Windows
The only file flag that os.chmod supports on Windows is the readonly flag,
which we definitely don't care to copy.
diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -683,19 +683,20 @@
d, fn = os.path.split(name)
fd, temp = tempfile.mkstemp(prefix='.%s-' % fn, dir=d)
os.close(fd)
- # Temporary files are created with mode 0600, which is usually not
- # what we want. If the original file already exists, just copy
- # its mode. Otherwise, manually obey umask.
- try:
- st_mode = os.lstat(name).st_mode & 0777
- except OSError, inst:
- if inst.errno != errno.ENOENT:
- raise
- st_mode = createmode
- if st_mode is None:
- st_mode = ~umask
- st_mode &= 0666
- os.chmod(temp, st_mode)
+ if os.name != 'nt':
+ # Temporary files are created with mode 0600, which is usually not
+ # what we want. If the original file already exists, just copy
+ # its mode. Otherwise, manually obey umask.
+ try:
+ st_mode = os.lstat(name).st_mode & 0777
+ except OSError, inst:
+ if inst.errno != errno.ENOENT:
+ raise
+ st_mode = createmode
+ if st_mode is None:
+ st_mode = ~umask
+ st_mode &= 0666
+ os.chmod(temp, st_mode)
if emptyok:
return temp
try:
More information about the Mercurial-devel
mailing list