[FIX] hw_drivers: get IoT log file instead of Internal Server Error

Before this commit:
 Using the "Download logs" button from the IoT box form view will
fail every time due to an Internal Server Error on the IoT side.
```py
File "/home/pi/odoo/odoo/tools/misc.py", line 189, in file_path
FileNotFoundError: File not found: /var/log/odoo/odoo-server.log
```
This happened due to changes introduced in:
https://github.com/odoo/odoo/pull/99658

The changes enforced to double check that the file path was in an
odoo addons (for security reasons).
However, it is generally not the case, thus the error

After this commit:
The log file is downloaded as intended

opw-3827121

closes odoo/odoo#160576

X-original-commit: a7aa4c6e58d6448556c85c393f2910490a0519f5
Signed-off-by: Loan Sens (lse) <lse@odoo.com>
This commit is contained in:
Loan (LSE)
2024-04-05 10:30:40 +00:00
parent 3da6cbfbea
commit ccbfdea3dc
+15 -2
View File
@@ -7,6 +7,7 @@ import logging
import os
import subprocess
import time
from zlib import adler32
from odoo import http, tools
@@ -78,7 +79,19 @@ class DriverController(http.Controller):
"""
Downloads the log file
"""
if tools.config['logfile']:
return http.Stream.from_path(tools.config['logfile']).get_response(
log_path = tools.config['logfile']
if log_path:
check = adler32(log_path.encode())
stat = os.stat(log_path)
# intentionally don't use Stream.from_path as the path used is not in the addons path
# for instance, for the iot-box it will be in /var/log/odoo
return http.Stream(
type='path',
path=log_path,
download_name=os.path.basename(log_path),
etag=f'{int(stat.st_mtime)}-{stat.st_size}-{check}',
last_modified=stat.st_mtime,
size=stat.st_size,
).get_response(
mimetype='text/plain', as_attachment=True
)