Comment 0 for bug 1640305

Revision history for this message
Larry Price (larryprice) wrote :

snapcraft version 2.21+17.10

When building my snap using the python plugin, I get the following error:

    Traceback (most recent call last):
      File "/usr/bin/snapcraft", line 31, in <module>
        snapcraft.main.main()
      File "/usr/lib/python3/dist-packages/snapcraft/main.py", line 234, in main
        return run(args, project_options)
      File "/usr/lib/python3/dist-packages/snapcraft/main.py", line 290, in run
        lifecycle.snap(project_options, args['<directory>'], args['--output'])
      File "/usr/lib/python3/dist-packages/snapcraft/internal/lifecycle.py", line 289, in snap
        snap = execute('prime', project_options)
      File "/usr/lib/python3/dist-packages/snapcraft/internal/lifecycle.py", line 103, in execute
        _Executor(config, project_options).run(step, part_names)
      File "/usr/lib/python3/dist-packages/snapcraft/internal/lifecycle.py", line 161, in run
        self._run_step(step, part, part_names)
      File "/usr/lib/python3/dist-packages/snapcraft/internal/lifecycle.py", line 197, in _run_step
        getattr(part, step)()
      File "/usr/lib/python3/dist-packages/snapcraft/internal/pluginhandler.py", line 305, in build
        self.code.build()
      File "/usr/lib/python3/dist-packages/snapcraft/plugins/python.py", line 263, in build
        r'#!/usr/bin/env python')
      File "/usr/lib/python3/dist-packages/snapcraft/file_utils.py", line 39, in replace_in_file
        search_pattern, replacement)
      File "/usr/lib/python3/dist-packages/snapcraft/file_utils.py", line 145, in _search_and_replace_contents
        with open(file_path, 'r+') as f:
    PermissionError: [Errno 13] Permission denied: '/home/lrp/Projects/2016/snap-libertine/parts/libertine-tools/install/etc/sudoers.d/libertine-lxc-sudo'

The file libertine-lxc-sudo is installed as readonly. The error is caused by the python plugin's indiscriminate r+ open of every file. Easy fix by adding an "except PermissionError" around the open or checking for write permissions on the file.