Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/export case insensitive #8585

Merged
merged 7 commits into from Mar 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 4 additions & 6 deletions conans/client/file_copier.py
Expand Up @@ -154,21 +154,19 @@ def _filter_files(src, pattern, links, excludes, ignore_case, excluded_folders):
filenames.append(relative_name)

if ignore_case:
filenames = {f.lower(): f for f in filenames}
pattern = pattern.lower()
files_to_copy = fnmatch.filter(filenames, pattern)
files_to_copy = [n for n in filenames if fnmatch.fnmatch(os.path.normpath(n.lower()),
pattern)]
else:
files_to_copy = [n for n in filenames if fnmatch.fnmatchcase(os.path.normpath(n),
pattern)]

for exclude in excludes:
if ignore_case:
files_to_copy = [f for f in files_to_copy if not fnmatch.fnmatch(f, exclude)]
files_to_copy = [f for f in files_to_copy if not fnmatch.fnmatch(f.lower(), exclude)]
else:
files_to_copy = [f for f in files_to_copy if not fnmatch.fnmatchcase(f, exclude)]

if ignore_case:
files_to_copy = [filenames[f] for f in files_to_copy]

return files_to_copy, linked_folders

@staticmethod
Expand Down
31 changes: 31 additions & 0 deletions conans/test/functional/command/export/export_test.py
@@ -1,4 +1,5 @@
import os
import platform
import stat
import textwrap
import unittest
Expand Down Expand Up @@ -462,3 +463,33 @@ def test_export_conflict_no_user_channel(self):
self.assertIn("pkg/0.1: A new conanfile.py version was exported", client.out)
client.run('export . Pkg/0.1@', assert_error=True)
self.assertIn("ERROR: Cannot export package with same name but different case", client.out)


@pytest.mark.skipif(platform.system() != "Linux", reason="Needs case-sensitive filesystem")
def test_export_casing():
# https://github.com/conan-io/conan/issues/8583
client = TestClient()
conanfile = textwrap.dedent("""
from conans import ConanFile
class Pkg(ConanFile):
exports = "file1", "FILE1"
exports_sources = "test", "TEST"
""")
client.save({"conanfile.py": conanfile,
"test": "some lowercase",
"TEST": "some UPPERCASE",
"file1": "file1 lowercase",
"FILE1": "file1 UPPERCASE"
})
assert client.load("test") == "some lowercase"
assert client.load("TEST") == "some UPPERCASE"
assert client.load("file1") == "file1 lowercase"
assert client.load("FILE1") == "file1 UPPERCASE"
client.run("export . pkg/0.1@")
ref = ConanFileReference.loads("pkg/0.1@")
export_src_folder = client.cache.package_layout(ref).export_sources()
assert load(os.path.join(export_src_folder, "test")) == "some lowercase"
assert load(os.path.join(export_src_folder, "TEST")) == "some UPPERCASE"
exports_folder = client.cache.package_layout(ref).export()
assert load(os.path.join(exports_folder, "file1")) == "file1 lowercase"
assert load(os.path.join(exports_folder, "FILE1")) == "file1 UPPERCASE"