Merge "bug 1166263 image-update handling for closed stdin"
This commit is contained in:
@@ -113,19 +113,26 @@ def _set_data_field(fields, args):
|
|||||||
if args.file:
|
if args.file:
|
||||||
fields['data'] = open(args.file, 'rb')
|
fields['data'] = open(args.file, 'rb')
|
||||||
else:
|
else:
|
||||||
# We distinguish between cases where image data is pipelined:
|
# distinguish cases where:
|
||||||
# (1) glance ... < /tmp/file or cat /tmp/file | glance ...
|
# (1) stdin is not valid (as in cron jobs):
|
||||||
# and cases where no image data is provided:
|
# glance ... <&-
|
||||||
# (2) glance ...
|
# (2) image data is provided through standard input:
|
||||||
if (sys.stdin.isatty() is not True):
|
# glance ... < /tmp/file or cat /tmp/file | glance ...
|
||||||
# Our input is from stdin, and we are part of
|
# (3) no image data provided:
|
||||||
# a pipeline, so data may be present. (We are of
|
# glance ...
|
||||||
# type (1) above.)
|
try:
|
||||||
|
os.fstat(0)
|
||||||
|
except OSError:
|
||||||
|
# (1) stdin is not valid (closed...)
|
||||||
|
fields['data'] = None
|
||||||
|
return
|
||||||
|
if not sys.stdin.isatty():
|
||||||
|
# (2) image data is provided through standard input
|
||||||
if msvcrt:
|
if msvcrt:
|
||||||
msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY)
|
msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY)
|
||||||
fields['data'] = sys.stdin
|
fields['data'] = sys.stdin
|
||||||
else:
|
else:
|
||||||
# We are of type (2) above, no image data supplied
|
# (3) no image data provided
|
||||||
fields['data'] = None
|
fields['data'] = None
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user