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.
This commit is contained in:
Jun Wu 2017-03-26 17:59:33 -07:00
parent 00bc5a1203
commit fea7f2c74c

View File

@ -788,14 +788,17 @@ def debugfileset(ui, repo, expr, **opts):
@command('debugfsinfo', [], _('[PATH]'), norepo=True) @command('debugfsinfo', [], _('[PATH]'), norepo=True)
def debugfsinfo(ui, path="."): def debugfsinfo(ui, path="."):
"""show information detected about current filesystem""" """show information detected about current filesystem"""
util.writefile('.debugfsinfo', '')
ui.write(('exec: %s\n') % (util.checkexec(path) and 'yes' or 'no')) ui.write(('exec: %s\n') % (util.checkexec(path) and 'yes' or 'no'))
ui.write(('fstype: %s\n') % (util.getfstype(path) or '(unknown)')) ui.write(('fstype: %s\n') % (util.getfstype(path) or '(unknown)'))
ui.write(('symlink: %s\n') % (util.checklink(path) and 'yes' or 'no')) 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(('hardlink: %s\n') % (util.checknlink(path) and 'yes' or 'no'))
ui.write(('case-sensitive: %s\n') % (util.fscasesensitive('.debugfsinfo') casesensitive = '(unknown)'
and 'yes' or 'no')) try:
util.tryunlink('.debugfsinfo') 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', @command('debuggetbundle',
[('H', 'head', [], _('id of head node'), _('ID')), [('H', 'head', [], _('id of head node'), _('ID')),