diff options
| author | Jairo Llopis <yajo.sk8@gmail.com> | 2016-06-13 13:53:48 +0200 |
|---|---|---|
| committer | Martin Trigaux <mat@odoo.com> | 2016-07-12 17:21:50 +0200 |
| commit | ee365bbf98fb1edbc9860c6302bbd8e0d376ef72 (patch) | |
| tree | 48ae04a464d7c60e0a4a2ad4eae310c9d12f6527 | |
| parent | d7d07810aa3b567a4258ea97d14aa43ddb49e9c7 (diff) | |
[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
| -rw-r--r-- | openerp/modules/module.py | 11 |
1 files 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) |
