Skip to content

Commit

Permalink
Make a copy of the snapcraft files common list before using it. (cano…
Browse files Browse the repository at this point in the history
…nical#767)

LP: #1614913.
  • Loading branch information
come-maiz authored and sergiusens committed Aug 30, 2016
1 parent e4504dd commit 19c64f6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
13 changes: 7 additions & 6 deletions snapcraft/internal/sources.py
Expand Up @@ -58,19 +58,20 @@
"""


import copy
import glob
import logging
import os
import stat
import os.path
import stat
import re
import requests
import shutil
import tarfile
import re
import subprocess
import tempfile
import tarfile
import zipfile
import glob


from snapcraft.internal import common
from snapcraft import file_utils
Expand Down Expand Up @@ -357,7 +358,7 @@ def pull(self):

def ignore(directory, files):
if directory is source_abspath:
ignored = common.SNAPCRAFT_FILES
ignored = copy.copy(common.SNAPCRAFT_FILES)
relative_cwd = os.path.basename(os.getcwd())
if os.path.join(directory, relative_cwd) == os.getcwd():
# Source is a parent of the working directory.
Expand Down
14 changes: 13 additions & 1 deletion snapcraft/tests/test_sources.py
Expand Up @@ -14,14 +14,18 @@
# 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 copy
import os
import http.server
import threading
import unittest.mock

import fixtures

from snapcraft.internal import sources
from snapcraft.internal import (
common,
sources
)
from snapcraft import tests


Expand Down Expand Up @@ -385,6 +389,8 @@ def test_init_with_source_branch_and_tag_raises_exception(self):
class TestLocal(tests.TestCase):

def test_pull_with_source_a_parent_of_current_dir(self):
snapcraft_files_before_pull = copy.copy(common.SNAPCRAFT_FILES)

# Verify that the snapcraft root dir does not get copied into itself.
os.makedirs('subdir')

Expand All @@ -397,6 +403,12 @@ def test_pull_with_source_a_parent_of_current_dir(self):
self.assertTrue(
'subdir' not in os.listdir(os.path.join('subdir', 'foo')))

# Regression test for https://bugs.launchpad.net/snapcraft/+bug/1614913
# Verify that SNAPCRAFT_FILES was not modified by the pull when there
# are files to ignore.
self.assertEqual(
snapcraft_files_before_pull, common.SNAPCRAFT_FILES)

def test_pull_with_existing_empty_source_dir_creates_hardlinks(self):
os.makedirs(os.path.join('src', 'dir'))
open(os.path.join('src', 'dir', 'file'), 'w').close()
Expand Down

0 comments on commit 19c64f6

Please sign in to comment.