[PATCH] clone on Windows: abort on reserved filenames

Adrian Buehlmann adrian at cadifra.com
Tue Jun 10 10:49:51 CDT 2008


testsuite passed on FreeBSD 6.2

# HG changeset patch
# User Adrian Buehlmann <adrian at cadifra.com>
# Date 1213107699 -7200
# Node ID a10c7fb7b2aca45d580c4854685d4875c5e708b7
# Parent  a51093361e1c76cf27124a76417fc118d8fa60c1
clone on Windows: abort on reserved filenames

hg clone hangs forever on Windows when pulling from
a remote repository (on unix) containing a file with
a filename equal to a Windows reserved filename.
With this change, hg clone now aborts with an error
message.
See also issue793.

diff -r a51093361e1c -r a10c7fb7b2ac mercurial/localrepo.py
--- a/mercurial/localrepo.py	Sat Jun 07 17:52:00 2008 +0200
+++ b/mercurial/localrepo.py	Tue Jun 10 16:21:39 2008 +0200
@@ -2003,6 +2003,8 @@
             self.ui.status(_("adding file changes\n"))
             while 1:
                 f = changegroup.getchunk(source)
+                if not util.validpathname(f):
+                    raise util.Abort(_("filename %s is not supported") % f)
                 if not f:
                     break
                 self.ui.debug(_("adding %s revisions\n") % f)
diff -r a51093361e1c -r a10c7fb7b2ac mercurial/util.py
--- a/mercurial/util.py	Sat Jun 07 17:52:00 2008 +0200
+++ b/mercurial/util.py	Tue Jun 10 16:21:39 2008 +0200
@@ -936,6 +936,9 @@
 def lookup_reg(key, name=None, scope=None):
     return None

+def validpathname(path):
+    return True
+
 # Platform specific variants
 if os.name == 'nt':
     import msvcrt
@@ -1854,3 +1857,12 @@
     scheme, netloc, path, params, query, fragment = urlparse.urlparse(url)
     netloc = netloc[netloc.find('@')+1:]
     return urlparse.urlunparse((scheme, netloc, path, params, query, fragment))
+
+_reserved_filenames = '''CON PRN AUX NUL
+    COM1 COM2 COM3 COM4 COM5 COM6 COM7 COM8 COM9
+    LPT1 LPT2 LPT3 LPT4 LPT5 LPT6 LPT7 LPT8 LPT9'''.split()
+def validpathname(path):
+    for n in path.split('/'):
+        if n.upper() in _reserved_filenames:
+            return False
+    return True


More information about the Mercurial-devel mailing list