From 64ab4a6914dadd741cfe61d9bd1959ae4509a1ca Mon Sep 17 00:00:00 2001
From: Martin Trigaux <mat@odoo.com>
Date: Thu, 14 Sep 2023 16:06:44 +0200
Subject: [PATCH] [FIX] module: use file_path

The method get_resource_path is redundant with file_path but without
all the checks.
The method will be deprecated in master but make it use file_path in
stable.

closes odoo/odoo#135896

Signed-off-by: Martin Trigaux (mat) <mat@odoo.com>
---
 odoo/modules/module.py | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/odoo/modules/module.py b/odoo/modules/module.py
index 3fc85ef4774f..7fda7cb8068c 100644
--- a/odoo/modules/module.py
+++ b/odoo/modules/module.py
@@ -16,6 +16,8 @@ import odoo
 import odoo.tools as tools
 import odoo.release as release
 from odoo.tools import pycompat
+from odoo.tools.misc import file_path
+
 
 MANIFEST_NAMES = ('__manifest__.py', '__openerp__.py')
 README = ['README.rst', 'README.md', 'README.txt']
@@ -166,6 +168,8 @@ def get_module_path(module, downloaded=False, display_warning=True):
     path if nothing else is found.
 
     """
+    if re.search(r"[\/\\]", module):
+        return False
     for adp in odoo.addons.__path__:
         files = [opj(adp, module, manifest) for manifest in MANIFEST_NAMES] +\
                 [opj(adp, module + '.zip')]
@@ -214,19 +218,19 @@ def get_resource_path(module, *args):
 
     :rtype: str
     :return: absolute path to the resource
-
-    TODO make it available inside on osv object (self.get_resource_path)
     """
-    mod_path = get_module_path(module)
-    if not mod_path:
+    resource_path = opj(module, *args)
+    try:
+        return file_path(resource_path)
+    except (FileNotFoundError, ValueError):
         return False
-    return check_resource_path(mod_path, *args)
 
 def check_resource_path(mod_path, *args):
     resource_path = opj(mod_path, *args)
-    if os.path.exists(resource_path):
-        return resource_path
-    return False
+    try:
+        return file_path(resource_path)
+    except (FileNotFoundError, ValueError):
+        return False
 
 # backwards compatibility
 get_module_resource = get_resource_path
-- 
GitLab