[PATCH 2 of 2] debugfsinfo: improve case-sensitive testing

Jun Wu quark at fb.com
Sun Mar 26 21:33:39 EDT 2017


# HG changeset patch
# User Jun Wu <quark at fb.com>
# Date 1490576373 25200
#      Sun Mar 26 17:59:33 2017 -0700
# Node ID 38ff33314869869535eb8f5c9cf4fa688847010e
# Parent  0b8f4bab3597b1621c07bfc82b9c16a77459a9b1
# Available At https://bitbucket.org/quark-zju/hg-draft
#              hg pull https://bitbucket.org/quark-zju/hg-draft -r 38ff33314869
debugfsinfo: improve case-sensitive testing

Previously the case-sensitive test was for the current directory, and is
fragile with errors, and could remove a real file called ".debugfsinfo".

This patch improves the case-sensitive testing so it test the given path
using a unique temporary file, and does not crash on errors.

diff --git a/mercurial/debugcommands.py b/mercurial/debugcommands.py
--- a/mercurial/debugcommands.py
+++ b/mercurial/debugcommands.py
@@ -789,12 +789,15 @@ def debugfileset(ui, repo, expr, **opts)
 def debugfsinfo(ui, path="."):
     """show information detected about current filesystem"""
-    util.writefile('.debugfsinfo', '')
     ui.write(('exec: %s\n') % (util.checkexec(path) and 'yes' or 'no'))
     ui.write(('fstype: %s\n') % (util.getfstype(path) or '(unknown)'))
     ui.write(('symlink: %s\n') % (util.checklink(path) and 'yes' or 'no'))
     ui.write(('hardlink: %s\n') % (util.checknlink(path) and 'yes' or 'no'))
-    ui.write(('case-sensitive: %s\n') % (util.fscasesensitive('.debugfsinfo')
-                                and 'yes' or 'no'))
-    util.tryunlink('.debugfsinfo')
+    casesensitive = '(unknown)'
+    try:
+        with tempfile.NamedTemporaryFile(prefix='.debugfsinfo', dir=path) as f:
+            casesensitive = util.fscasesensitive(f.name) and 'yes' or 'no'
+    except OSError:
+        pass
+    ui.write(('case-sensitive: %s\n') % casesensitive)
 
 @command('debuggetbundle',


More information about the Mercurial-devel mailing list