diff options
author | Alberto Sartori <alberto.sartori@huawei.com> | 2023-07-21 11:26:52 +0200 |
---|---|---|
committer | Alberto Sartori <alberto.sartori@huawei.com> | 2023-07-21 14:08:29 +0200 |
commit | 629dc072c7c81693e55cafaa90e63ff1128b0efe (patch) | |
tree | 54960c37839b1ef388d50444414795d78298a6c2 | |
parent | 5548997571612cb8a78dfa9ac50ed690a28341ca (diff) | |
download | justbuild-629dc072c7c81693e55cafaa90e63ff1128b0efe.tar.gz |
bugfix: stage symlinks as symlinks when creating an action directory
Before this patch, when creating an action directory, symlinks were
staged as regular files.
-rw-r--r-- | src/buildtool/execution_api/local/local_action.cpp | 12 | ||||
-rwxr-xr-x | test/buildtool/execution_engine/executor/executor_api.test.hpp | 6 | ||||
-rw-r--r-- | test/end-to-end/TARGETS | 1 | ||||
-rw-r--r-- | test/end-to-end/symlinks/TARGETS | 8 | ||||
-rw-r--r-- | test/end-to-end/symlinks/stage-links.sh | 55 |
5 files changed, 78 insertions, 4 deletions
diff --git a/src/buildtool/execution_api/local/local_action.cpp b/src/buildtool/execution_api/local/local_action.cpp index d42dcdd6..d3ad7fd9 100644 --- a/src/buildtool/execution_api/local/local_action.cpp +++ b/src/buildtool/execution_api/local/local_action.cpp @@ -185,6 +185,18 @@ auto LocalAction::StageFile(std::filesystem::path const& target_path, return false; } + if (info.type == ObjectType::Symlink) { + auto to = + FileSystemManager::ReadContentAtPath(*blob_path, ObjectType::File); + if (not to) { + logger_.Emit(LogLevel::Error, + "could not read content of symlink {}", + (*blob_path).string()); + return false; + } + return FileSystemManager::CreateSymlink(*to, target_path); + } + return FileSystemManager::CreateDirectory(target_path.parent_path()) and FileSystemManager::CreateFileHardlink(*blob_path, target_path); } diff --git a/test/buildtool/execution_engine/executor/executor_api.test.hpp b/test/buildtool/execution_engine/executor/executor_api.test.hpp index 30d724ea..ffee5184 100755 --- a/test/buildtool/execution_engine/executor/executor_api.test.hpp +++ b/test/buildtool/execution_engine/executor/executor_api.test.hpp @@ -398,11 +398,9 @@ static inline void TestUploadAndDownloadTrees(ApiFactory const& factory, CHECK(FileSystemManager::IsDirectory(tmpdir)); CHECK(FileSystemManager::IsDirectory(tmpdir / "b")); CHECK(FileSystemManager::IsFile(tmpdir / "a")); - // echo command returns regular file instead of symlink - CHECK(FileSystemManager::IsFile(tmpdir / "b" / "a")); + CHECK(FileSystemManager::IsNonUpwardsSymlink(tmpdir / "b" / "a")); CHECK(*FileSystemManager::ReadFile(tmpdir / "a") == "foo"); - // echo command returns regular file instead of symlink - CHECK(*FileSystemManager::ReadFile(tmpdir / "b" / "a") == "bar"); + CHECK(*FileSystemManager::ReadSymlink(tmpdir / "b" / "a") == "bar"); REQUIRE(FileSystemManager::RemoveDirectory(tmpdir, true)); } diff --git a/test/end-to-end/TARGETS b/test/end-to-end/TARGETS index 0e81d749..be1f642f 100644 --- a/test/end-to-end/TARGETS +++ b/test/end-to-end/TARGETS @@ -58,6 +58,7 @@ , [["./", "git-import", "TESTS"], "git-import"] , [["./", "gc", "TESTS"], "gc"] , [["./", "execution-service", "TESTS"], "execution-service"] + , [["./", "symlinks", "TESTS"], "symlinks"] ] } } diff --git a/test/end-to-end/symlinks/TARGETS b/test/end-to-end/symlinks/TARGETS new file mode 100644 index 00000000..12add451 --- /dev/null +++ b/test/end-to-end/symlinks/TARGETS @@ -0,0 +1,8 @@ +{ "stage-links": + { "type": ["end-to-end", "with remote"] + , "name": ["stage-links"] + , "test": ["stage-links.sh"] + , "deps": [["end-to-end", "tool-under-test"]] + } +, "TESTS": {"type": "install", "tainted": ["test"], "deps": ["stage-links"]} +} diff --git a/test/end-to-end/symlinks/stage-links.sh b/test/end-to-end/symlinks/stage-links.sh new file mode 100644 index 00000000..b8234d2a --- /dev/null +++ b/test/end-to-end/symlinks/stage-links.sh @@ -0,0 +1,55 @@ +#!/bin/sh +# Copyright 2023 Huawei Cloud Computing Technology Co., Ltd. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -eu + +readonly JUST="${PWD}/bin/tool-under-test" + +touch ROOT +cat > TARGETS <<EOF +{ "input": + { "type": "generic" + , "out_dirs": ["."] + , "cmds": ["touch foo", "ln -s foo bar", "ln -s iNeXIstENt baz"] + } +, "stage-links": + { "type": "generic" + , "out_dirs": ["."] + , "cmds": + [ "test -L bar || (printf \"\n\nwrong staging: bar must be a symlink\n\n\" && exit 1)" + , "test -L baz || (printf \"\n\nwrong staging: baz must be a symlink\n\n\" && exit 1)" + , "! test -e iNeXIstENt" + ] + , "deps": ["input"] + } +} +EOF + +ARGS="--local-build-root=.root" +if [ "${COMPATIBLE:-}" = "YES" ]; then + NAME="compatible" + ARGS="$ARGS --compatible" +fi + +REMOTE_EXECUTION_ARGS="-r ${REMOTE_EXECUTION_ADDRESS}" +if [ "${REMOTE_EXECUTION_PROPERTIES:-}" != "" ]; then + REMOTE_EXECUTION_ARGS="${REMOTE_EXECUTION_ARGS} --remote-execution-property ${REMOTE_EXECUTION_PROPERTIES}" +fi + +echo "test staging locally" +${JUST} build ${ARGS} stage-links + +echo "test staging remotely" +${JUST} build ${ARGS} ${REMOTE_EXECUTION_ARGS} stage-links |