Anonymous avatar Anonymous committed a5ab8e5

libutils: handle paths with distinct real names

Comments (0)

Files changed (1)

rope/base/libutils.py

     `Project.get_file()`, and `Project.get_folder()` methods.
 
     """
-    path = rope.base.project._realpath(path)
-    project_path = path
-    if path == project.address or path.startswith(project.address + os.sep):
-        project_path = path[len(project.address):].lstrip('/' + os.sep)
-    else:
+    project_path = relative(project.address, path)
+    if project_path is None:
+        project_path = rope.base.project._realpath(path)
         project = rope.base.project.get_no_project()
     if type is None:
         return project.get_resource(project_path)
         return project.get_folder(project_path)
     return None
 
+def relative(root, path):
+    root = rope.base.project._realpath(root)
+    path = rope.base.project._realpath(path)
+    rel = []
+    while True:
+        if os.path.samefile(root, path):
+            return '/'.join(rel)
+        parent = os.path.dirname(path)
+        if not path or parent == path:
+            break
+        rel.append(os.path.basename(path))
+        path = parent
 
 def report_change(project, path, old_content):
     """Report that the contents of file at `path` was changed
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.