Read-only files cause PermissionError with python plugin

Bug #1640305 reported by Larry Price
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Snapcraft
Fix Released
Low
Larry Price

Bug Description

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.

Larry Price (larryprice)
description: updated
Revision history for this message
Larry Price (larryprice) wrote :
Changed in snapcraft:
milestone: none → 2.24
assignee: nobody → Larry Price (larryprice)
status: New → In Progress
importance: Undecided → Low
status: In Progress → Fix Committed
Kyle Fazzari (kyrofa)
Changed in snapcraft:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.