changeset 45149:87047efbc6a6

debugcommands: create new debugantivirusrunning command This writes the EICAR test file to .hg/cache, in an attempt to trigger an AV scanner's scanning engine. This should let us (in theory) detect some cases when a user's slowness is a result of AV scanning. Differential Revision: https://phab.mercurial-scm.org/D8353
author Augie Fackler <augie@google.com>
date Wed, 01 Apr 2020 08:42:00 -0500
parents a37f290a7124
children dc5e5577af39
files mercurial/debugcommands.py tests/test-completion.t tests/test-help.t
diffstat 3 files changed, 21 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/debugcommands.py	Fri Jul 17 03:28:52 2020 +0200
+++ b/mercurial/debugcommands.py	Wed Apr 01 08:42:00 2020 -0500
@@ -127,6 +127,23 @@
     ui.write(b'%d:%s\n' % (r.rev(a), hex(a)))
 
 
+@command(b'debugantivirusrunning', [])
+def debugantivirusrunning(ui, repo):
+    """attempt to trigger an antivirus scanner to see if one is active"""
+    with repo.cachevfs.open('eicar-test-file.com', b'wb') as f:
+        f.write(
+            util.b85decode(
+                # This is a base85-armored version of the EICAR test file. See
+                # https://en.wikipedia.org/wiki/EICAR_test_file for details.
+                b'ST#=}P$fV?P+K%yP+C|uG$>GBDK|qyDK~v2MM*<JQY}+dK~6+LQba95P'
+                b'E<)&Nm5l)EmTEQR4qnHOhq9iNGnJx'
+            )
+        )
+    # Give an AV engine time to scan the file.
+    time.sleep(2)
+    util.unlink(repo.cachevfs.join('eicar-test-file.com'))
+
+
 @command(b'debugapplystreamclonebundle', [], b'FILE')
 def debugapplystreamclonebundle(ui, repo, fname):
     """apply a stream clone bundle file"""
--- a/tests/test-completion.t	Fri Jul 17 03:28:52 2020 +0200
+++ b/tests/test-completion.t	Wed Apr 01 08:42:00 2020 -0500
@@ -74,6 +74,7 @@
 Show debug commands if there are no other candidates
   $ hg debugcomplete debug
   debugancestor
+  debugantivirusrunning
   debugapplystreamclonebundle
   debugbackupbundle
   debugbuilddag
@@ -261,6 +262,7 @@
   continue: dry-run
   copy: forget, after, at-rev, force, include, exclude, dry-run
   debugancestor: 
+  debugantivirusrunning: 
   debugapplystreamclonebundle: 
   debugbackupbundle: recover, patch, git, limit, no-merges, stat, graph, style, template
   debugbuilddag: mergeable-file, overwritten-file, new-file
--- a/tests/test-help.t	Fri Jul 17 03:28:52 2020 +0200
+++ b/tests/test-help.t	Wed Apr 01 08:42:00 2020 -0500
@@ -971,6 +971,8 @@
   
    debugancestor
                  find the ancestor revision of two revisions in a given index
+   debugantivirusrunning
+                 attempt to trigger an antivirus scanner to see if one is active
    debugapplystreamclonebundle
                  apply a stream clone bundle file
    debugbackupbundle