Skip to content

Commit

Permalink
Merge pull request #407 from sergiusens/bugfix/1561331/clean_icon_paths
Browse files Browse the repository at this point in the history
Clear icon path before trying to write the new one
  • Loading branch information
sergiusens committed Mar 28, 2016
2 parents 8be249f + 9b750b2 commit b18e4e9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
5 changes: 4 additions & 1 deletion snapcraft/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,10 @@ def _setup_assets(meta_dir, config_data):
icon_ext = config_data['icon'].split(os.path.extsep)[1]
icon_dir = os.path.join(meta_dir, 'gui')
icon_path = os.path.join(icon_dir, 'icon.{}'.format(icon_ext))
os.mkdir(icon_dir)
if not os.path.exists(icon_dir):
os.mkdir(icon_dir)
if os.path.exists(icon_path):
os.unlink(icon_path)
os.link(config_data['icon'], icon_path)

_setup_from_setup(meta_dir)
Expand Down
24 changes: 24 additions & 0 deletions snapcraft/tests/test_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import logging
import os
from unittest.mock import patch

import fixtures
import yaml

from snapcraft import (
Expand Down Expand Up @@ -143,6 +145,9 @@ def test_create_meta_with_declared_icon(self):
'icon found in snap.yaml {}'.format(y))

def test_create_meta_with_declared_icon_and_setup(self):
fake_logger = fixtures.FakeLogger(level=logging.INFO)
self.useFixture(fake_logger)

gui_path = os.path.join('setup', 'gui')
os.makedirs(gui_path)
icon_content = b'this is the icon'
Expand All @@ -163,11 +168,30 @@ def test_create_meta_with_declared_icon_and_setup(self):
self.assertTrue(
os.path.exists(self.snap_yaml), 'snap.yaml was not created')

self.assertTrue(
"DEPRECATED: 'icon' defined in snapcraft.yaml"
in fake_logger.output, 'Missing deprecation message for icon')

with open(self.snap_yaml) as f:
y = yaml.load(f)
self.assertFalse('icon' in y,
'icon found in snap.yaml {}'.format(y))

def test_create_meta_with_declared_icon_and_setup_ran_twice_ok(self):
gui_path = os.path.join('setup', 'gui')
os.makedirs(gui_path)
icon_content = b'this is the icon'
with open(os.path.join(gui_path, 'icon.png'), 'wb') as f:
f.write(icon_content)

open(os.path.join(os.curdir, 'my-icon.png'), 'w').close()
self.config_data['icon'] = 'my-icon.png'

meta.create(self.config_data)

# Running again should be good
meta.create(self.config_data)

def test_create_meta_with_icon_in_setup(self):
gui_path = os.path.join('setup', 'gui')
os.makedirs(gui_path)
Expand Down

0 comments on commit b18e4e9

Please sign in to comment.