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 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions conans/client/file_copier.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ def _filter_files(src, pattern, links, excludes, ignore_case, excluded_folders):
relative_path = os.path.relpath(root, src)
compare_relative_path = relative_path.lower() if ignore_case else relative_path
for exclude in excludes:
if ignore_case:
exclude = exclude.lower()
Copy link
Member

@uilianries uilianries Mar 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

at line 121 it does the same.

Suggested change
exclude = exclude.lower()
exclude = exclude.lower()

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point. But need to remove the 2 lines.

if fnmatch.fnmatch(compare_relative_path, exclude):
subfolders[:] = []
files = []
Expand All @@ -154,21 +156,20 @@ 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)]
exclude = exclude.lower()
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
Original file line number Diff line number Diff line change
@@ -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"