Patchwork [1,of,4] py3: read/write plain lock file in binary mode

login
register
mail settings
Submitter Yuya Nishihara
Date March 6, 2018, 12:54 p.m.
Message ID <faea088aebdbda2e32e5.1520340886@mimosa>
Download mbox | patch
Permalink /patch/29061/
State Accepted
Headers show

Comments

Yuya Nishihara - March 6, 2018, 12:54 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1520205676 18000
#      Sun Mar 04 18:21:16 2018 -0500
# Node ID faea088aebdbda2e32e5339cbb6df51283fe2f56
# Parent  4c71a26a4009d88590c9ae3d64a5912fd556d82e
py3: read/write plain lock file in binary mode

A lock file shouldn't contain '\n', so this isn't a BC.
Pulkit Goyal - March 8, 2018, 6:40 p.m.
Queued the series. Many thanks!

On Tue, Mar 6, 2018 at 6:24 PM, Yuya Nishihara <yuya@tcha.org> wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1520205676 18000
> #      Sun Mar 04 18:21:16 2018 -0500
> # Node ID faea088aebdbda2e32e5339cbb6df51283fe2f56
> # Parent  4c71a26a4009d88590c9ae3d64a5912fd556d82e
> py3: read/write plain lock file in binary mode
>
> A lock file shouldn't contain '\n', so this isn't a BC.
>
> diff --git a/contrib/python3-whitelist b/contrib/python3-whitelist
> --- a/contrib/python3-whitelist
> +++ b/contrib/python3-whitelist
> @@ -373,6 +373,7 @@ test-subrepo-deep-nested-change.t
>  test-subrepo.t
>  test-symlinks.t
>  test-tag.t
> +test-tags.t
>  test-treemanifest.t
>  test-unamend.t
>  test-uncommit.t
> diff --git a/mercurial/util.py b/mercurial/util.py
> --- a/mercurial/util.py
> +++ b/mercurial/util.py
> @@ -1689,7 +1689,8 @@ def makelock(info, pathname):
>      except AttributeError: # no symlink in os
>          pass
>
> -    ld = os.open(pathname, os.O_CREAT | os.O_WRONLY | os.O_EXCL)
> +    flags = os.O_CREAT | os.O_WRONLY | os.O_EXCL | getattr(os, 'O_BINARY', 0)
> +    ld = os.open(pathname, flags)
>      os.write(ld, info)
>      os.close(ld)
>
> @@ -1701,7 +1702,7 @@ def readlock(pathname):
>              raise
>      except AttributeError: # no symlink in os
>          pass
> -    fp = posixfile(pathname)
> +    fp = posixfile(pathname, 'rb')
>      r = fp.read()
>      fp.close()
>      return r
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Patch

diff --git a/contrib/python3-whitelist b/contrib/python3-whitelist
--- a/contrib/python3-whitelist
+++ b/contrib/python3-whitelist
@@ -373,6 +373,7 @@  test-subrepo-deep-nested-change.t
 test-subrepo.t
 test-symlinks.t
 test-tag.t
+test-tags.t
 test-treemanifest.t
 test-unamend.t
 test-uncommit.t
diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -1689,7 +1689,8 @@  def makelock(info, pathname):
     except AttributeError: # no symlink in os
         pass
 
-    ld = os.open(pathname, os.O_CREAT | os.O_WRONLY | os.O_EXCL)
+    flags = os.O_CREAT | os.O_WRONLY | os.O_EXCL | getattr(os, 'O_BINARY', 0)
+    ld = os.open(pathname, flags)
     os.write(ld, info)
     os.close(ld)
 
@@ -1701,7 +1702,7 @@  def readlock(pathname):
             raise
     except AttributeError: # no symlink in os
         pass
-    fp = posixfile(pathname)
+    fp = posixfile(pathname, 'rb')
     r = fp.read()
     fp.close()
     return r