Ticket #1893: 0001-Actually-fix-Firefox-file-prefix-path-error.patch

File 0001-Actually-fix-Firefox-file-prefix-path-error.patch, 1.7 KB (added by Simon80, 12 years ago)
  • deluge/ui/gtkui/ipcinterface.py

    From 234b000e481d105ae9026abccb93e9bc63564d6a Mon Sep 17 00:00:00 2001
    From: Simon Ruggier <Simon80@gmail.com>
    Date: Wed, 7 Sep 2011 18:42:42 -0400
    Subject: [PATCH] Actually fix Firefox "file://" prefix path error
    
    Firefox passes file arguments to Deluge as file:// URLs instead of local
    paths, for some reason. In 1.3.2, these weren't handled at all, which
    resulted in errors. Since then, a change was made to handle these URLs
    by stripping the file:// off of the front of the URL and treating the
    rest like a valid path. However, this isn't enough, since URLs also
    escape special characters using %xx escape sequences. This change
    handles those using the urllib.url2pathname function, which converts URL
    escaped path components into local paths.
    ---
     deluge/ui/gtkui/ipcinterface.py |    6 +++++-
     1 files changed, 5 insertions(+), 1 deletions(-)
    
    diff --git a/deluge/ui/gtkui/ipcinterface.py b/deluge/ui/gtkui/ipcinterface.py
    index ef6b104..fcea626 100644
    a b  
    3737import sys 
    3838import os 
    3939import base64 
     40import urllib 
    4041 
    4142try: 
    4243    import rencode 
    def process_args(args): 
    209210                client.core.add_torrent_magnet(arg, {}) 
    210211        else: 
    211212            # Just a file 
    212             path = os.path.abspath(arg.replace('file://', '', 1)) 
     213            path = arg 
     214            if path.startswith("file://"): 
     215                path = urllib.url2pathname(path.replace('file://', '', 1)) 
     216            path = os.path.abspath(path) 
    213217            log.debug("Attempting to add %s from external source..", path) 
    214218            if not os.path.exists(path): 
    215219                log.error("No such file: %s", path)