[FIX] hw_drivers: delete old files before download
When some clients are upgrading their databates and reconnect their IoT Boxes to the new version of the database, we currently can have an issue where the old iot handlers are not being overwritten, but the new ones are being deleted. This happens in situations like where we add a new driver distinction in Windows, so its name "SomeDriver.py" becomes "SomeDriver_W.py". Since we dont delete SomeDriver.py the IoT can have both drivers in such situations, causing conflicts and unwanted behaviors. The goal here is to delete all the old drivers and interfaces before downloading the new ones to make sure we don't have this issus task-3729890 closes odoo/odoo#159538 X-original-commit: 53a04406e6563d141b7b2378dc25b29b8a8086d6 Signed-off-by: Quentin Lejeune (qle) <qle@odoo.com>
This commit is contained in:
@@ -341,6 +341,22 @@ def load_certificate():
|
||||
start_nginx_server()
|
||||
return True
|
||||
|
||||
def delete_iot_handlers():
|
||||
"""
|
||||
Delete all the drivers and interfaces
|
||||
This is needed to avoid conflicts
|
||||
with the newly downloaded drivers
|
||||
"""
|
||||
try:
|
||||
for directory in ['drivers', 'interfaces']:
|
||||
path = file_path(f'hw_drivers/iot_handlers/{directory}')
|
||||
iot_handlers = list_file_by_os(path)
|
||||
for file in iot_handlers:
|
||||
unlink_file(f"odoo/addons/hw_drivers/iot_handlers/{directory}/{file}")
|
||||
_logger.info("Deleted old IoT handlers")
|
||||
except OSError:
|
||||
_logger.exception('Failed to delete old IoT handlers')
|
||||
|
||||
def download_iot_handlers(auto=True):
|
||||
"""
|
||||
Get the drivers from the configured Odoo server
|
||||
@@ -353,6 +369,7 @@ def download_iot_handlers(auto=True):
|
||||
try:
|
||||
resp = pm.request('POST', server, fields={'mac': get_mac_address(), 'auto': auto}, timeout=8)
|
||||
if resp.data:
|
||||
delete_iot_handlers()
|
||||
with writable():
|
||||
drivers_path = ['odoo', 'addons', 'hw_drivers', 'iot_handlers']
|
||||
path = path_file(str(Path().joinpath(*drivers_path)))
|
||||
|
||||
Reference in New Issue
Block a user