changeset 46892:4a6024b87dfc

blackbox: fix type error on log rotation on read-only filesystem Grepping around, the code uses either encoding.strtolocal or stringutil.forcebytestr in this situation. No idea which is best. Differential Revision: https://phab.mercurial-scm.org/D10293
author Valentin Gatien-Baron <vgatien-baron@janestreet.com>
date Wed, 31 Mar 2021 17:54:02 -0400
parents c6ceb5f27f97
children 3d32b9759047
files mercurial/loggingutil.py tests/test-blackbox.t
diffstat 2 files changed, 17 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/loggingutil.py	Thu Apr 08 14:38:27 2021 +0200
+++ b/mercurial/loggingutil.py	Wed Mar 31 17:54:02 2021 -0400
@@ -10,7 +10,10 @@
 
 import errno
 
-from . import pycompat
+from . import (
+    encoding,
+    pycompat,
+)
 
 from .utils import (
     dateutil,
@@ -32,7 +35,7 @@
             if err.errno != errno.ENOENT:
                 ui.debug(
                     b"warning: cannot remove '%s': %s\n"
-                    % (newpath, err.strerror)
+                    % (newpath, encoding.strtolocal(err.strerror))
                 )
         try:
             if newpath:
@@ -41,7 +44,7 @@
             if err.errno != errno.ENOENT:
                 ui.debug(
                     b"warning: cannot rename '%s' to '%s': %s\n"
-                    % (newpath, oldpath, err.strerror)
+                    % (newpath, oldpath, encoding.strtolocal(err.strerror))
                 )
 
     if maxsize > 0:
--- a/tests/test-blackbox.t	Thu Apr 08 14:38:27 2021 +0200
+++ b/tests/test-blackbox.t	Wed Mar 31 17:54:02 2021 -0400
@@ -317,6 +317,17 @@
   1970/01/01 00:00:00 bob @45589e459b2edfbf3dbde7e01f611d2c1e7453d7 (5000)> --debug log -r tip exited 0 after *.?? seconds (glob)
   1970/01/01 00:00:00 bob @45589e459b2edfbf3dbde7e01f611d2c1e7453d7 (5000)> blackbox
 
+Skip rotation if the .hg is read-only
+
+#if unix-permissions
+  $ chmod -w .hg
+  $ hg log -r. -T '{rev}\n' --config blackbox.maxsize=1 --debug
+  warning: cannot rename '$TESTTMP/blackboxtest3/.hg/blackbox.log.1' to '$TESTTMP/blackboxtest3/.hg/blackbox.log': Permission denied
+  warning: cannot write to blackbox.log: Permission denied
+  1
+  $ chmod +w .hg
+#endif
+
 Test log recursion from dirty status check
 
   $ cat > ../r.py <<EOF