Skip to content

Commit 8d2aed9

Browse files
committed
[FIX] hw_drivers: ensure lib directory before iterdir
We now also delete `lib/` directory before deleting/downloading new IoT handlers. In community, this directory does not exist, resulting in Path error while trying to `iterdir()` on it. We now look for files recursively inside `iot_handlers/`, and provide the list to the updated method `unlink_file` that now accepts multiple arguments to avoid excessively switching between rw/ro filesystem modes. closes odoo#193990 Signed-off-by: Yaroslav Soroko (yaso) <yaso@odoo.com>
1 parent 08ecb25 commit 8d2aed9

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

addons/hw_drivers/tools/helpers.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -397,17 +397,17 @@ def load_certificate():
397397

398398

399399
def delete_iot_handlers():
400-
"""
401-
Delete all the drivers and interfaces
402-
This is needed to avoid conflicts
403-
with the newly downloaded drivers
400+
"""Delete all drivers, interfaces and libs if any.
401+
This is needed to avoid conflicts with the newly downloaded drivers.
404402
"""
405403
try:
406-
for directory in ['drivers', 'interfaces', 'lib']:
407-
iot_handlers = file_path(f'hw_drivers/iot_handlers/{directory}')
408-
for file in Path(iot_handlers).iterdir():
409-
if file.is_file():
410-
unlink_file(f"odoo/addons/hw_drivers/iot_handlers/{directory}/{file.name}")
404+
iot_handlers = Path(file_path(f'hw_drivers/iot_handlers'))
405+
filenames = [
406+
f"odoo/addons/hw_drivers/iot_handlers/{file.relative_to(iot_handlers)}"
407+
for file in iot_handlers.glob('**/*')
408+
if file.is_file()
409+
]
410+
unlink_file(*filenames)
411411
_logger.info("Deleted old IoT handlers")
412412
except OSError:
413413
_logger.exception('Failed to delete old IoT handlers')
@@ -491,11 +491,12 @@ def read_file_first_line(filename):
491491
return f.readline().strip('\n')
492492

493493

494-
def unlink_file(filename):
494+
def unlink_file(*filenames):
495495
with writable():
496-
path = path_file(filename)
497-
if path.exists():
498-
path.unlink()
496+
for filename in filenames:
497+
path = path_file(filename)
498+
if path.exists():
499+
path.unlink()
499500

500501

501502
def write_file(filename, text, mode='w'):

0 commit comments

Comments
 (0)