[meld] meldapp: Handle opening ambiguous relative paths (bgo#742142)



commit 2d6860d5c1b670726663d3a4ef9a1f5b8214f6ca
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Thu Jan 1 09:20:44 2015 +1000

    meldapp: Handle opening ambiguous relative paths (bgo#742142)
    
    Because GApplicationCommandLine.create_file_for_arg() handles absolute
    and relative paths *and* URIs, it will try to interpret some relative
    path names (e.g., foo:bar) as a URI.
    
    This patch fixes this by checking to see whether the created file
    exists, and if not attempts to treat it as a relative path name. The
    extra cwd handling is necessary due to GApplication remote invocation.

 meld/meldapp.py |   13 ++++++++++++-
 1 files changed, 12 insertions(+), 1 deletions(-)
---
diff --git a/meld/meldapp.py b/meld/meldapp.py
index 34df96b..766c6b9 100644
--- a/meld/meldapp.py
+++ b/meld/meldapp.py
@@ -301,12 +301,23 @@ class MeldApp(Gtk.Application):
                 return parser.exit_status
             return tab
 
+        def make_file_from_command_line(arg):
+            f = command_line.create_file_for_arg(arg)
+            if not f.query_exists():
+                # May be a relative path with ':', misinterpreted as a URI
+                cwd = Gio.File.new_for_path(command_line.get_cwd())
+                relative = Gio.File.resolve_relative_path(cwd, arg)
+                if relative.query_exists():
+                    return relative
+                # Return the original arg for a better error message
+            return f
+
         tab = None
         error = None
         comparisons = options.diff + [args]
         options.newtab = options.newtab or not command_line.get_is_remote()
         for i, paths in enumerate(comparisons):
-            files = [command_line.create_file_for_arg(p) for p in paths]
+            files = [make_file_from_command_line(p) for p in paths]
             auto_merge = (
                 options.auto_merge if i == len(comparisons) - 1 else False)
             try:


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]