Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#4450 closed defect (fixed)

Sugar needs to be able to launch applications when ~/.i18n missing or corrupt

Reported by: greenfeld Owned by: erikos
Priority: High Milestone:
Component: Sugar Version: 0.98.x
Severity: Major Keywords:
Cc: dsd Distribution/OS: OLPC
Bug Status: Unconfirmed

Description

Sugar needs to be able to launch applications when ~/.i18n (with the LANG variable) is missing or corrupt.

Reuben updated a XO-1.5 from OLPC 11.3.1 to 13.1.0 os30 where the ~/.i18n file had a length of zero. After upgrading he was not able to launch any applications.

The traceback seen was:

Traceback (most recent call last):
  File "/usr/bin/sugar-activity", line 160, in <module>
    main()
  File "/usr/bin/sugar-activity", line 109, in main
    locale_path = i18n.get_locale_path(bundle.get_bundle_id())
  File "/usr/lib/python2.7/site-packages/sugar3/activity/i18n.py", line 142, in get_locale_path
    bundle_id + '.mo')
  File "/usr/lib/python2.7/posixpath.py", line 66, in join
    if b.startswith('/'):
AttributeError: 'NoneType' object has no attribute 'startswith'
Exited with status 1, pid 866 data (None, <open file '<fdopen>', mode 'w' at 0x9b14758>, dbus.ByteArray('9780179d63598547ed68c0f9e3fa2275ac2ce898', variant_level=1))

Attachments (1)

0001-i18n-get_locale_path-handle-the-case-when-the-defaul.patch (2.6 KB) - added by erikos 11 years ago.
i18n get_locale_path: handle the case when the default locale is not set

Download all attachments as: .zip

Change History (10)

comment:1 Changed 11 years ago by erikos

Thanks for the writeup, reproduced here. In get_locale_path we use locale.getdefaultlocale() which returns (None, None) in the case where '.i18n' is not present, leading to the traceback from above.

comment:2 Changed 11 years ago by erikos

On the XO, the '.i18n' file is written from olpc-configure. It says there that, "these don't need to be repeated when we upgrade.", maybe there should be a check if the file got corrupted on an upgrade.

Additionally, the Sugar code should probably be fallback to en_US if the default locale can not be retrieved, and even if unlikely to not be set, do not assume it is set.

comment:3 Changed 11 years ago by erikos

  • Cc dsd added

comment:4 Changed 11 years ago by erikos

  • Milestone changed from Unspecified by Release Team to 0.98
  • Priority changed from Unspecified by Maintainer to High
[erikos@t61 sugar-toolkit-gtk3]$ git diff src/sugar3/activity/i18n.py
diff --git a/src/sugar3/activity/i18n.py b/src/sugar3/activity/i18n.py
index 8b8e663..ca8cda4 100644
--- a/src/sugar3/activity/i18n.py
+++ b/src/sugar3/activity/i18n.py
@@ -135,10 +135,14 @@ def get_locale_path(bundle_id):
 
     candidate_dirs[os.path.join(sys.prefix, 'share', 'locale')] = 0
 
+    default_locale = locale.getdefaultlocale()[0]
+    if not default_locale:
+        default_locale = 'en_US'
+
     for candidate_dir in candidate_dirs.keys():
         if os.path.exists(candidate_dir):
             full_path = os.path.join(candidate_dir, \
-                locale.getdefaultlocale()[0], 'LC_MESSAGES', \
+                default_locale, 'LC_MESSAGES', \
                 bundle_id + '.mo')
             if os.path.exists(full_path):
                 try:

comment:5 Changed 11 years ago by dsd

olpc-configure is not the right place to protect against any kind of corruption that may occur. Sugar simply needs to become more resilient.

I don't think that default_locale fallback looks correct. I would say that you should simply not do anything with locale if locale settings cannot be read.

Changed 11 years ago by erikos

i18n get_locale_path: handle the case when the default locale is not set

comment:6 Changed 11 years ago by erikos

  • Keywords r? added

New patch that does handle the case when the default locale is not present in a way Daniel suggested.

comment:7 Changed 11 years ago by dsd

Looks good to me. Thanks.

comment:8 Changed 11 years ago by erikos

  • Keywords r? removed
  • Resolution set to fixed
  • Status changed from new to closed

toolkit fix:

master: dcbdcd77fe803ca12d5b973ea3764d2042a9a991

0.98: 06d671a01deda02170e62bf376673b8dd3ecd052

Sugar does handle the case fine now, and activities can be started if the default locale is not set.

OLPC: I wonder if the olpc-upgrade code should not rewrite the .i18n file if it gets corrupted on an upgrade. Is it possible to add a check there? Is there some code that does so already?

comment:9 Changed 11 years ago by dnarvaez

  • Milestone 0.98 deleted

Milestone 0.98 deleted

Note: See TracTickets for help on using tickets.