Signed-off-by: Rob Browning <
r...@defaultvalue.org>
Tested-by: Rob Browning <
r...@defaultvalue.org>
---
Proposed for main.
lib/bup/helpers.py | 38 +-------------------------------------
test/int/test_helpers.py | 29 +----------------------------
2 files changed, 2 insertions(+), 65 deletions(-)
diff --git a/lib/bup/helpers.py b/lib/bup/helpers.py
index 32bafeca..69896b4e 100644
--- a/lib/bup/helpers.py
+++ b/lib/bup/helpers.py
@@ -1,8 +1,7 @@
"""Helper functions and classes for bup."""
from contextlib import ExitStack, nullcontext
-from ctypes import sizeof, c_void_p
-from os import environ, fsencode
+from os import fsencode
from random import SystemRandom
from subprocess import PIPE, Popen
from tempfile import mkdtemp
@@ -337,41 +336,6 @@ def readpipe(argv, preexec_fn=None, shell=False):
return exo(argv, preexec_fn=preexec_fn, shell=shell)[0]
-def _argmax_base(command):
- base_size = 2048
- for c in command:
- base_size += len(command) + 1
- for k, v in environ.items():
- base_size += len(k) + len(v) + 2 + sizeof(c_void_p)
- return base_size
-
-
-def _argmax_args_size(args):
- return sum(len(x) + 1 + sizeof(c_void_p) for x in args)
-
-
-def batchpipe(command, args, preexec_fn=None, arg_max=sc_arg_max):
- """If args is not empty, yield the output produced by calling the
-command list with args as a sequence of strings (It may be necessary
-to return multiple strings in order to respect ARG_MAX)."""
- # The optional arg_max arg is a workaround for an issue with the
- # current wvtest behavior.
- base_size = _argmax_base(command)
- while args:
- room = arg_max - base_size
- i = 0
- while i < len(args):
- next_size = _argmax_args_size(args[i:i+1])
- if room - next_size < 0:
- break
- room -= next_size
- i += 1
- sub_args = args[:i]
- args = args[i:]
- assert(len(sub_args))
- yield readpipe(command + sub_args, preexec_fn=preexec_fn)
-
-
def resolve_parent(p):
"""Return the absolute path of a file without following any final symlink.
diff --git a/test/int/test_helpers.py b/test/int/test_helpers.py
index 287d131d..19b1d366 100644
--- a/test/int/test_helpers.py
+++ b/test/int/test_helpers.py
@@ -6,7 +6,7 @@ from bup import helpers
from wvpytest import *
from bup.compat import environ
-from bup.helpers import (atomically_replaced_file, batchpipe, detect_fakeroot,
+from bup.helpers import (atomically_replaced_file, detect_fakeroot,
grafted_path_components, parse_num,
path_components, readpipe, stripped_path_components,
shstr,
@@ -118,33 +118,6 @@ def test_readpipe():
WVPASSEQ(str(ex), rx)
-def test_batchpipe():
- for chunk in batchpipe([b'echo'], []):
- WVPASS(False)
- out = b''
- for chunk in batchpipe([b'echo'], [b'42']):
- out += chunk
- WVPASSEQ(out, b'42\n')
- try:
- batchpipe([b'bash', b'-c'], [b'exit 42'])
- except Exception as ex:
- WVPASSEQ(str(ex),
- "subprocess 'bash -c exit 42' failed with status 42")
- args = [str(x) for x in range(6)]
- # Force batchpipe to break the args into batches of 3. This
- # approach assumes all args are the same length.
- arg_max = \
- helpers._argmax_base([b'echo']) + helpers._argmax_args_size(args[:3])
- batches = batchpipe(['echo'], args, arg_max=arg_max)
- WVPASSEQ(next(batches), b'0 1 2\n')
- WVPASSEQ(next(batches), b'3 4 5\n')
- WVPASSEQ(next(batches, None), None)
- batches = batchpipe([b'echo'], [str(x) for x in range(5)], arg_max=arg_max)
- WVPASSEQ(next(batches), b'0 1 2\n')
- WVPASSEQ(next(batches), b'3 4\n')
- WVPASSEQ(next(batches, None), None)
-
-
@pytest.mark.parametrize('sync_atomic_replace', (True, False))
def test_atomically_replaced_file(sync_atomic_replace, tmpdir):
target_file = os.path.join(tmpdir, b'test-atomic-write')
--
2.47.3