sugarlabs / sugar-toolkit-gtk3

Sugar Learning Environment, Activity Toolkit, GTK 3.
GNU Lesser General Public License v2.1
21 stars 80 forks source link

Fix ls-files quoting #457

Closed quozl closed 3 years ago

quozl commented 3 years ago

File names are quoted and then mishandled by the builder. http://lists.sugarlabs.org/archive/sugar-devel/2021-February/058971.html

Use null-terminated files.

Untested.

chimosky commented 3 years ago

Tested, goes into an infinite loop with error;

Traceback (most recent call last):
  File "./setup.py", line 20, in <module>
    bundlebuilder.start()
  File "/usr/lib/python3.7/dist-packages/sugar3/activity/bundlebuilder.py", line 651, in start
    globals()['cmd_' + (options.command or '')](config, options)
  File "/usr/lib/python3.7/dist-packages/sugar3/activity/bundlebuilder.py", line 514, in cmd_dist_source
    packager.package()
  File "/usr/lib/python3.7/dist-packages/sugar3/activity/bundlebuilder.py", line 272, in package
    for f in self.get_files_in_git():
  File "/usr/lib/python3.7/dist-packages/sugar3/activity/bundlebuilder.py", line 222, in get_files_in_git
    sub_list = self.get_files_in_git(sub_path)
  File "/usr/lib/python3.7/dist-packages/sugar3/activity/bundlebuilder.py", line 222, in get_files_in_git
    sub_list = self.get_files_in_git(sub_path)
  File "/usr/lib/python3.7/dist-packages/sugar3/activity/bundlebuilder.py", line 222, in get_files_in_git
    sub_list = self.get_files_in_git(sub_path)
  [Previous line repeated 984 more times]
  File "/usr/lib/python3.7/dist-packages/sugar3/activity/bundlebuilder.py", line 196, in get_files_in_git
    cwd=root)
  File "/usr/lib/python3.7/subprocess.py", line 775, in __init__
    restore_signals, start_new_session)
  File "/usr/lib/python3.7/subprocess.py", line 1443, in _execute_child
    for dir in os.get_exec_path(env))
  File "/usr/lib/python3.7/os.py", line 634, in get_exec_path
    warnings.simplefilter("ignore", BytesWarning)
  File "/usr/lib/python3.7/warnings.py", line 179, in simplefilter
    _add_filter(action, None, category, None, lineno, append=append)
  File "/usr/lib/python3.7/warnings.py", line 186, in _add_filter
    filters.remove(item)
RecursionError: maximum recursion depth exceeded in comparison

Looking more into it.

chimosky commented 3 years ago

Took a look and I'm yet to figure out why it goes into an infinite loop even when ignore is True.

quozl commented 3 years ago

Looked into it, but could not reproduce your problem easily. Used https://github.com/sugarlabs/flipsticks/commit/eb48ca9e8fee74ae7863c0c6448acb8797f4529f.

/home/guest/flipsticks-activity/po/hus.po:209: duplicate message definition...
/home/guest/flipsticks-activity/po/hus.po:207: ...this is the location of the first definition
msgfmt: found 1 fatal error
ERROR - msgfmt failed with return code 1.
Traceback (most recent call last):
  File "/home/guest/flipsticks-activity/./setup.py", line 20, in <module>
    bundlebuilder.start()
  File "/usr/lib/python3/dist-packages/sugar3/activity/bundlebuilder.py", line 649, in start
    globals()['cmd_' + (options.command or '')](config, options)
  File "/usr/lib/python3/dist-packages/sugar3/activity/bundlebuilder.py", line 496, in cmd_dist_xo
    packager = XOPackager(Builder(config, no_fail))
  File "/usr/lib/python3/dist-packages/sugar3/activity/bundlebuilder.py", line 243, in __init__
    self.builder.build_locale()
  File "/usr/lib/python3/dist-packages/sugar3/activity/bundlebuilder.py", line 159, in build_locale
    cat = gettext.GNUTranslations(open(mo_file, 'rb'))
FileNotFoundError: [Errno 2] No such file or directory: '/home/guest/flipsticks-activity/locale/hus/LC_MESSAGES/org.worldwideworkshop.olpc.FlipSticks.mo'

Removing po/hus.po does uncover;

Traceback (most recent call last):
  File "/home/guest/flipsticks-activity/./setup.py", line 20, in <module>
    bundlebuilder.start()
  File "/usr/lib/python3/dist-packages/sugar3/activity/bundlebuilder.py", line 649, in start
    globals()['cmd_' + (options.command or '')](config, options)
  File "/usr/lib/python3/dist-packages/sugar3/activity/bundlebuilder.py", line 497, in cmd_dist_xo
    packager.package()
  File "/usr/lib/python3/dist-packages/sugar3/activity/bundlebuilder.py", line 252, in package
    bundle_zip.write(os.path.join(self.config.source_dir, f),
  File "/usr/lib/python3.9/zipfile.py", line 1727, in write
    zinfo = ZipInfo.from_file(filename, arcname,
  File "/usr/lib/python3.9/zipfile.py", line 501, in from_file
    st = os.stat(filename)
FileNotFoundError: [Errno 2] No such file or directory: '/home/guest/flipsticks-activity/"lessons/es/Introducci\\303\\263n.txt"'

Made a local copy of sugar3;

guest@bullseye:~/flipsticks-activity$ sudo cp -rl /usr/lib/python3/dist-packages/sugar3 .
guest@bullseye:~/flipsticks-activity$ sudo chown -R guest:guest sugar3
guest@bullseye:~/flipsticks-activity$ ./setup.py dist_xo
Traceback (most recent call last):
  File "/home/guest/flipsticks-activity/./setup.py", line 20, in <module>
    bundlebuilder.start()
  File "/home/guest/flipsticks-activity/sugar3/activity/bundlebuilder.py", line 649, in start
    globals()['cmd_' + (options.command or '')](config, options)
  File "/home/guest/flipsticks-activity/sugar3/activity/bundlebuilder.py", line 497, in cmd_dist_xo
    packager.package()
  File "/home/guest/flipsticks-activity/sugar3/activity/bundlebuilder.py", line 252, in package
    bundle_zip.write(os.path.join(self.config.source_dir, f),
  File "/usr/lib/python3.9/zipfile.py", line 1727, in write
    zinfo = ZipInfo.from_file(filename, arcname,
  File "/usr/lib/python3.9/zipfile.py", line 501, in from_file
    st = os.stat(filename)
FileNotFoundError: [Errno 2] No such file or directory: '/home/guest/flipsticks-activity/"lessons/es/Introducci\\303\\263n.txt"'

Paths in traceback show local bundlebuilder is used. Check.

Applied my patch, and a CPU loop occurs for a while then RecursionError.

It would appear the coding is not defensive. :grin:

Pushed a fix.

chimosky commented 3 years ago

Tested, works as expected. Thanks.