From ee365bbf98fb1edbc9860c6302bbd8e0d376ef72 Mon Sep 17 00:00:00 2001 From: Jairo Llopis Date: Mon, 13 Jun 2016 13:53:48 +0200 Subject: [PATCH] [FIX] modules: choose the right addons path When launching a server with two similar addons path, e.g.: - /home/alice/dev - /home/alice/devodoo launching the server in dev mode may crash due to the poor matching using `path.startswith(...)` method which may make `/home/alice/devodoo/bob/main.xml` match in addons folder `/home/alice/dev` and with a non-exitant local path `odoo/bob/main.xml`. Instead of relying on the name, use the `os.path.commonprefix()` method to match on real paths and avoid partial matching. commonprefix will only work if the folder name ends with the appropriate separator (which is not guarantee for a user provided addons-path) so force a trailing `/` using os.path.join(..., '')`. Closes #12359 --- openerp/modules/module.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/openerp/modules/module.py b/openerp/modules/module.py index e50ba86fc39..1ea82fa3906 100644 --- a/openerp/modules/module.py +++ b/openerp/modules/module.py @@ -177,9 +177,16 @@ def get_resource_from_path(path): :rtype: tuple :return: tuple(module_name, relative_path, os_relative_path) if possible, else None """ - resource = [path.replace(adpath, '') for adpath in ad_paths if path.startswith(adpath)] + resource = False + for adpath in ad_paths: + # force trailing separator + adpath = os.path.join(adpath, "") + if os.path.commonprefix([adpath, path]) == adpath: + resource = path.replace(adpath, "", 1) + break + if resource: - relative = resource[0].split(os.path.sep) + relative = resource.split(os.path.sep) if not relative[0]: relative.pop(0) module = relative.pop(0)