Commit b21fbe23 authored by Kirill Smelkov's avatar Kirill Smelkov

zodbcommit: Fix stdin reading on py3

Zodbcommit reads input in zodbdump format from stdin and then uses
zodbdump.DumpReader to parser that input. The parser works on binary
data.

However zodbcommit, was preparing that input data mixing bytes and
strings, which is failing on py3:

    (py3.venv) kirr@deca:~/src/wendelin/z/zodbtools$ zodb commit 1.fs 00
    Ignoring index for /home/kirr/src/wendelin/z/zodbtools/1.fs
    aaa
    Traceback (most recent call last):
      File "/home/kirr/src/wendelin/venv/py3.venv/bin/zodb", line 33, in <module>
        sys.exit(load_entry_point('zodbtools', 'console_scripts', 'zodb')())
      File "/home/kirr/src/wendelin/z/zodbtools/zodbtools/zodb.py", line 129, in main
        return command_module.main(argv)
      File "/home/kirr/src/wendelin/venv/py3.venv/lib/python3.9/site-packages/decorator.py", line 232, in fun
        return caller(func, *(extras + args), **kw)
      File "/home/kirr/src/tools/go/pygolang/golang/__init__.py", line 103, in _
        return f(*argv, **kw)
      File "/home/kirr/src/wendelin/z/zodbtools/zodbtools/zodbcommit.py", line 222, in main
        zin += sys.stdin.read()
    TypeError: can't concat str to bytes

-> Fix it by reading stdin in binary mode.

No test currently as zodbcommit.main is not covered by tests (hopefully yet).
parent 69dc6de1
# Copyright (C) 2018-2021 Nexedi SA and Contributors.
# Copyright (C) 2018-2022 Nexedi SA and Contributors.
# Kirill Smelkov <kirr@nexedi.com>
#
# This program is free software: you can Use, Study, Modify and Redistribute
......@@ -40,7 +40,7 @@ can query current database head (last_tid) with `zodb info <stor> last_tid`.
from __future__ import print_function
from zodbtools import zodbdump
from zodbtools.util import ashex, fromhex, storageFromURL
from zodbtools.util import ashex, fromhex, storageFromURL, asbinstream
from ZODB.interfaces import IStorageRestoreable
from ZODB.utils import p64, u64, z64
from ZODB.POSException import POSKeyError
......@@ -219,7 +219,7 @@ def main(argv):
# artificial transaction header with tid=0 to request regular commit
zin = b'txn 0000000000000000 " "\n'
zin += sys.stdin.read()
zin += asbinstream(sys.stdin).read()
zin = BytesIO(zin)
zr = zodbdump.DumpReader(zin)
zr.lineno -= 1 # we prepended txn header
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment