Fix handling of dangling symlink on manifest generation

There may be broken symlinks within the log directories, those fail with
an error when os.stat() is executed on them. Let's just skip those.

Change-Id: I3e6982c53a08f57ac0e592b8a0041bbb39812d1f
This commit is contained in:
Jens Harbott 2019-08-26 13:50:03 +00:00
parent c74b03649a
commit dd40f5ed9f

View File

@ -67,14 +67,19 @@ def walk(root, original_root=None):
mime_guess, encoding = mimetypes.guess_type(path)
if not mime_guess:
mime_guess = 'text/plain'
st = os.stat(path)
last_modified = st[stat.ST_MTIME]
size = st[stat.ST_SIZE]
data.append(dict(name=f,
mimetype=mime_guess,
encoding=encoding,
last_modified=last_modified,
size=size))
# This may fail e.g. for dangling symlinks, just ignore those
try:
st = os.stat(path)
last_modified = st[stat.ST_MTIME]
size = st[stat.ST_SIZE]
data.append(dict(name=f,
mimetype=mime_guess,
encoding=encoding,
last_modified=last_modified,
size=size))
except FileNotFoundError:
continue
return data