Patchwork [2,of,2] debugfsinfo: improve case-sensitive testing

login
register
mail settings
Submitter Jun Wu
Date March 27, 2017, 1:33 a.m.
Message ID <38ff33314869869535eb.1490578419@localhost.localdomain>
Download mbox | patch
Permalink /patch/19719/
State Accepted
Headers show

Comments

Jun Wu - March 27, 2017, 1:33 a.m.
# HG changeset patch
# User Jun Wu <quark@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.

Patch

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',