Fix broken -f option on single files instead of directories

This commit is contained in:
Kristóf Tóth 2022-02-13 23:19:09 +01:00
parent f90ac943cf
commit 36c29627af

14
main.py
View File

@ -1,8 +1,11 @@
#!/usr/bin/env python3
# pylint: disable=consider-using-with
# (this code contains some IO stream juggling)
from sys import stdin
from sys import exit as sysexit
from io import BytesIO
from subprocess import Popen, PIPE
from pathlib import Path
import click
from blake3 import blake3
@ -42,7 +45,7 @@ def get_input_stream(kwargs):
if (text := kwargs["text"]) is not None:
stream = ClosableStream(BytesIO(text.encode()))
elif file := kwargs["file"]:
stream = get_deterministic_tar_stream(file)
stream = get_deterministic_stream(file)
elif not stdin.isatty():
stream = ClosableStream(stdin.buffer)
return stream
@ -57,8 +60,15 @@ class ClosableStream:
return self._close_func()
def get_deterministic_stream(file):
if Path(file).is_dir():
return get_deterministic_tar_stream(file)
ifile = open(file, 'rb')
return ClosableStream(ifile, ifile.close)
def get_deterministic_tar_stream(file):
# pylint: disable=consider-using-with
cmd = (
'tar',
f'--blocking-factor={BUF_SIZE//512}',