You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildstream.apache.org by tv...@apache.org on 2021/02/04 08:23:49 UTC
[buildstream] 01/02: Resolve paths before ordering them in
link_files/copy_files
This is an automated email from the ASF dual-hosted git repository.
tvb pushed a commit to branch valentindavid/link_files_sort_resolved
in repository https://gitbox.apache.org/repos/asf/buildstream.git
commit 96fc33105c3a14b24fcc4157ae576e21a9ea1070
Author: Valentin David <va...@codethink.co.uk>
AuthorDate: Fri Oct 5 16:20:55 2018 +0200
Resolve paths before ordering them in link_files/copy_files
Some paths may not be canonical, and sorting paths solves symlink
issues only when paths are canonical.
Fixes #647.
---
buildstream/utils.py | 11 +++++-
tests/integration/compose-symlink-order.py | 39 ++++++++++++++++++++++
.../project/elements/compose-symlink-order/a.bst | 4 +++
.../project/elements/compose-symlink-order/b.bst | 7 ++++
.../elements/compose-symlink-order/compose.bst | 8 +++++
.../project/files/compose-symlink-order/a/b/.keep | 0
.../project/files/compose-symlink-order/b/a/c/d | 1 +
7 files changed, 69 insertions(+), 1 deletion(-)
diff --git a/buildstream/utils.py b/buildstream/utils.py
index a460031..ae5da34 100644
--- a/buildstream/utils.py
+++ b/buildstream/utils.py
@@ -816,7 +816,16 @@ def _process_list(srcdir, destdir, filelist, actionfunc, result,
# symbolic links which lead to directories before processing files inside
# those directories.
if not presorted:
- filelist = sorted(filelist)
+ resolved = []
+ for f in filelist:
+ dirname = os.path.dirname(f)
+ dirname = os.path.realpath(os.path.join(srcdir, dirname))
+ dirname = os.path.relpath(dirname, srcdir)
+ if dirname == '.':
+ resolved.append(os.path.basename(f))
+ else:
+ resolved.append(os.path.join(dirname, os.path.basename(f)))
+ filelist = sorted(resolved)
# Now walk the list
for path in filelist:
diff --git a/tests/integration/compose-symlink-order.py b/tests/integration/compose-symlink-order.py
new file mode 100644
index 0000000..32a8582
--- /dev/null
+++ b/tests/integration/compose-symlink-order.py
@@ -0,0 +1,39 @@
+import os
+import pytest
+
+from buildstream import _yaml
+
+from tests.testutils import cli_integration as cli
+
+
+pytestmark = pytest.mark.integration
+
+
+DATA_DIR = os.path.join(
+ os.path.dirname(os.path.realpath(__file__)),
+ "project"
+)
+
+
+@pytest.mark.datafiles(DATA_DIR)
+def test_compose_symlinks_bad_order(cli, tmpdir, datafiles):
+ project = str(datafiles)
+ checkout = os.path.join(cli.directory, 'checkout')
+ element_path = os.path.join(project, 'elements')
+
+ a_files = os.path.join(project, 'files', 'compose-symlink-order', 'a')
+ os.symlink('b', os.path.join(a_files, 'a'),
+ target_is_directory=True)
+
+ result = cli.run(project=project,
+ args=['build', 'compose-symlink-order/compose.bst'])
+ result.assert_success()
+
+ result = cli.run(project=project,
+ args=['checkout', 'compose-symlink-order/compose.bst',
+ checkout])
+ result.assert_success()
+
+ assert os.path.exists(os.path.join(checkout, 'a/c/d'))
+ assert os.path.exists(os.path.join(checkout, 'b/c/d'))
+ assert os.path.islink(os.path.join(checkout, 'a'))
diff --git a/tests/integration/project/elements/compose-symlink-order/a.bst b/tests/integration/project/elements/compose-symlink-order/a.bst
new file mode 100644
index 0000000..16c7b8f
--- /dev/null
+++ b/tests/integration/project/elements/compose-symlink-order/a.bst
@@ -0,0 +1,4 @@
+kind: import
+sources:
+- kind: local
+ path: files/compose-symlink-order/a
diff --git a/tests/integration/project/elements/compose-symlink-order/b.bst b/tests/integration/project/elements/compose-symlink-order/b.bst
new file mode 100644
index 0000000..08bece2
--- /dev/null
+++ b/tests/integration/project/elements/compose-symlink-order/b.bst
@@ -0,0 +1,7 @@
+kind: import
+depends:
+- filename: compose-symlink-order/a.bst
+
+sources:
+- kind: local
+ path: files/compose-symlink-order/b
diff --git a/tests/integration/project/elements/compose-symlink-order/compose.bst b/tests/integration/project/elements/compose-symlink-order/compose.bst
new file mode 100644
index 0000000..3150724
--- /dev/null
+++ b/tests/integration/project/elements/compose-symlink-order/compose.bst
@@ -0,0 +1,8 @@
+kind: compose
+depends:
+- filename: compose-symlink-order/b.bst
+ type: build
+
+config:
+ exclude:
+ - devel
diff --git a/tests/integration/project/files/compose-symlink-order/a/b/.keep b/tests/integration/project/files/compose-symlink-order/a/b/.keep
new file mode 100644
index 0000000..e69de29
diff --git a/tests/integration/project/files/compose-symlink-order/b/a/c/d b/tests/integration/project/files/compose-symlink-order/b/a/c/d
new file mode 100644
index 0000000..9daeafb
--- /dev/null
+++ b/tests/integration/project/files/compose-symlink-order/b/a/c/d
@@ -0,0 +1 @@
+test