Check fd is reg file or symlink in get_length before using st_size.
st_size is not meaningful for non-regular files (or symlinks).
See man (2) stat.
@@ -11,6 +11,7 @@ from typing import ( # pylint: disable=unused-import
import logging
from os import fstat
+import stat
from io import (SEEK_END, SEEK_SET, UnsupportedOperation)
import isodate
@@ -70,6 +71,10 @@ def get_length(data):
pass
else:
try:
+ mode = fstat(fileno).st_mode
+ if stat.S_ISREG(mode) or stat.S_ISLNK(mode):
+ #st_size only meaningful if regular file or symlink, other types
+ # e.g. sockets may return misleading sizes like 0
return fstat(fileno).st_size
except OSError:
# Not a valid fileno, may be possible requests returned
