[PATCH] Purge crash on junction point

Mathieu Cantin mcantin at coveo.com
Tue Feb 18 17:08:35 CST 2014


# HG changeset patch
# User Mathieu Cantin <mcantin at coveo.com>
# Date 1392764497 18000
#      Tue Feb 18 18:01:37 2014 -0500
# Node ID bf485635a586a487a732ba27e122531235062da7
# Parent  0e2877f8605dcaf4fdf2ab7e0046f1f6f80161dd
purge: delete invalid junction point

When you have 2 folders linked to each other by a junction point. For exemple
"A" is a folder and "B" is a junction point to "A". "A" is deleted, then
os.listdir throws an error on "B" because the target of "B" doesn't exist
anymore.

diff -r 0e2877f8605d -r bf485635a586 hgext/purge.py
--- a/hgext/purge.py Sat Feb 15 22:09:32 2014 -0600
+++ b/hgext/purge.py Tue Feb 18 18:01:37 2014 -0500
@@ -95,6 +95,13 @@
             os.chmod(path, stat.S_IMODE(s.st_mode) | stat.S_IWRITE)
             os.remove(path)

+    def hasfilesindir(path):
+        try:
+            return len(os.listdir(path)) > 0
+        except OSError:
+            # It's a junction point with an invalid target
+            return False
+
     directories = []
     match = scmutil.match(repo[None], dirs, opts)
     match.explicitdir = match.traversedir = directories.append
@@ -105,6 +112,6 @@
         remove(removefile, f)

     for f in sorted(directories, reverse=True):
-        if match(f) and not os.listdir(repo.wjoin(f)):
+        if match(f) and not hasfilesindir(repo.wjoin(f)):
             ui.note(_('removing directory %s\n') % f)
-            remove(os.rmdir, f)
+            remove(os.rmdir, f)
\ No newline at end of file

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://selenic.com/pipermail/mercurial-devel/attachments/20140218/135f75a2/attachment.html>


More information about the Mercurial-devel mailing list