Refactor _util._is_file to handle detached sigs and data on stdin.
When gnupg.GPG.verify_file() was changed recently to take the filename of the signature file as an argument to GnuPG, and then take the data file to be verified on stdin, the parser in _parsers._check_options() would call _util._is_file(), which would return False and log an error that "'-' is not a file!". This fixes that issue by catching OSError and treating it differently. Additionally, I renamed the _util._is_file() parameter `input`→`filename` to avoid overriding a builtin method. I also replaced the `assert` lines with explicit checks, because `assert`s are stripped out when the Python interpreter is run with -OO. * FIXES an issue with verification of detached signatures whose datafiles are read from stdin.fix/30-hidden-recipient
parent
b90d3b6414
commit
f5b345b1ae
|
@ -303,22 +303,31 @@ def _has_readwrite(path):
|
|||
"""
|
||||
return os.access(path, os.R_OK ^ os.W_OK)
|
||||
|
||||
def _is_file(input):
|
||||
def _is_file(filename):
|
||||
"""Check that the size of the thing which is supposed to be a filename has
|
||||
size greater than zero, without following symbolic links or using
|
||||
:func:os.path.isfile.
|
||||
|
||||
:param input: An object to check.
|
||||
:param filename: An object to check.
|
||||
:rtype: bool
|
||||
:returns: True if :param:input is file-like, False otherwise.
|
||||
:returns: True if **filename** is file-like, False otherwise.
|
||||
"""
|
||||
try:
|
||||
assert os.lstat(input).st_size > 0, "not a file: %s" % input
|
||||
except (AssertionError, TypeError, IOError, OSError) as err:
|
||||
log.error(err.message, exc_info=1)
|
||||
return False
|
||||
statinfo = os.lstat(filename)
|
||||
log.debug("lstat(%r) with type=%s gave us %r"
|
||||
% (repr(filename), type(filename), repr(statinfo)))
|
||||
if not (statinfo.st_size > 0):
|
||||
raise ValueError("'%s' appears to be an empty file!" % filename)
|
||||
except OSError as oserr:
|
||||
log.error(oserr)
|
||||
if filename == '-':
|
||||
log.debug("Got '-' for filename, assuming sys.stdin...")
|
||||
return True
|
||||
except (ValueError, TypeError, IOError) as err:
|
||||
log.error(err)
|
||||
else:
|
||||
return True
|
||||
return False
|
||||
|
||||
def _is_stream(input):
|
||||
"""Check that the input is a byte stream.
|
||||
|
|
Loading…
Reference in New Issue