Ticket #1394: 1394-84.patch

File 1394-84.patch, 2.3 KB (added by erikos, 14 years ago)

Backported patch to 0.84

  • src/sugar/bundle/activitybundle.py

    diff --git a/src/sugar/bundle/activitybundle.py b/src/sugar/bundle/activitybundle.py
    index 268576e..2bec54f 100644
    a b class ActivityBundle(Bundle): 
    323323                os.makedirs(mime_pkg_dir)
    324324            installed_mime_path = os.path.join(mime_pkg_dir,
    325325                                               '%s.xml' % self._bundle_id)
    326             os.symlink(mime_path, installed_mime_path)
     326            self._symlink(mime_path, installed_mime_path)
    327327            os.spawnlp(os.P_WAIT, 'update-mime-database',
    328328                       'update-mime-database', mime_dir)
    329329
    class ActivityBundle(Bundle): 
    339339                                              mime_type.replace('/', '-'))
    340340                svg_file = mime_icon_base + '.svg'
    341341                info_file = mime_icon_base + '.icon'
    342                 if os.path.isfile(svg_file):
    343                     os.symlink(svg_file,
    344                                os.path.join(installed_icons_dir,
    345                                             os.path.basename(svg_file)))
    346                 if os.path.isfile(info_file):
    347                     os.symlink(info_file,
    348                                os.path.join(installed_icons_dir,
    349                                             os.path.basename(info_file)))
     342                self._symlink(svg_file,
     343                              os.path.join(installed_icons_dir,
     344                                           os.path.basename(svg_file)))
     345                self._symlink(info_file,
     346                              os.path.join(installed_icons_dir,
     347                                           os.path.basename(info_file)))
     348
    350349        return install_path
    351350
     351    def _symlink(self, src, dst):
     352        if not os.path.isfile(src):
     353            return
     354        if not os.path.islink(dst) and os.path.exists(dst):
     355            raise RuntimeError('Do not remove %s if it was not '
     356                               'installed by sugar', dst)
     357        logging.debug('Link resource %s to %s', src, dst)
     358        if os.path.lexists(dst):
     359            logging.debug('Relink %s', dst)
     360            os.unlink(dst)
     361        os.symlink(src, dst)
     362
    352363    def uninstall(self, install_path, force=False):
    353364        if os.path.islink(install_path):
    354365            # Don't remove the actual activity dir if it's a symbolic link