Ticket #1241: sugar-1241-base.patch

File sugar-1241-base.patch, 1.2 KB (added by alsroot, 12 years ago)
  • src/sugar/mime.py

    From 78ad10db61928ba53dc94a4ae51ce6c1d364bcef Mon Sep 17 00:00:00 2001
    From: Aleksey Lim <alsroot@member.fsf.org>
    Date: Wed, 2 Sep 2009 14:37:39 +0000
    Subject: Readlink before checking mime type
    
    ---
     src/sugar/mime.py |   13 ++++++++++++-
     1 files changed, 12 insertions(+), 1 deletions(-)
    
    diff --git a/src/sugar/mime.py b/src/sugar/mime.py
    index 8242dd4..45f1a9f 100644
    a b def get_all_generic_types(): 
    9090    return types
    9191
    9292def get_for_file(file_name):
     93    if file_name.startswith('file://'):
     94        file_name = file_name[7:]
     95
     96    if os.path.islink(file_name):
     97        symlink = os.readlink(file_name)
     98        if symlink.startswith('/'):
     99            file_name = symlink
     100        else:
     101            file_name = os.path.join(os.path.dirname(file_name), symlink)
     102
    93103    mime_type = _sugarbaseext.get_mime_type_for_file(file_name)
    94104    if mime_type == 'application/octet-stream':
    95105        if _file_looks_like_text(file_name):
    96106            return 'text/plain'
    97107        else:
    98108            return 'application/octet-stream'
     109
    99110    return mime_type
    100        
     111
    101112def get_from_file_name(file_name):
    102113    return _sugarbaseext.get_mime_type_from_file_name(file_name)
    103114