Move the last_bytes util method to libvirt

The only user of this util method is libvirt, so it should live there.
This is a precursor to re-writing its single caller to use privsep to
read bytes instead of chown'ing files.

Change-Id: Ice5cc70eeef3fbeee9a1a0ec0daa801c6f74480c
This commit is contained in:
Michael Still 2017-06-08 14:57:49 +10:00 committed by Tony Breeds
parent 3c1d175556
commit fffb1a1ef7

@ -20,7 +20,6 @@
import contextlib
import copy
import datetime
import errno
import functools
import hashlib
import inspect
@ -837,30 +836,6 @@ def mkfs(fs, path, label=None, run_as_root=False):
execute(*args, run_as_root=run_as_root)
def last_bytes(file_like_object, num):
"""Return num bytes from the end of the file, and remaining byte count.
:param file_like_object: The file to read
:param num: The number of bytes to return
:returns: (data, remaining)
"""
try:
file_like_object.seek(-num, os.SEEK_END)
except IOError as e:
# seek() fails with EINVAL when trying to go before the start of the
# file. It means that num is larger than the file size, so just
# go to the start.
if e.errno == errno.EINVAL:
file_like_object.seek(0, os.SEEK_SET)
else:
raise
remaining = file_like_object.tell()
return (file_like_object.read(), remaining)
def metadata_to_dict(metadata, include_deleted=False):
result = {}
for item in metadata: