Skip to content

Commit

Permalink
[FIX] hw_drivers: delete old files before download
Browse files Browse the repository at this point in the history
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#159538

X-original-commit: 53a0440
Signed-off-by: Quentin Lejeune (qle) <qle@odoo.com>
  • Loading branch information
Ysoroko committed Mar 28, 2024
1 parent 7cddd35 commit 2387777
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions addons/hw_drivers/tools/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)))
Expand Down

0 comments on commit 2387777

Please sign in to comment.