From d9ca907da8babe1d01f0e83eed1808fe4aca4747 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexis=20L=C3=B3pez=20Zubieta?= Date: Mon, 5 Nov 2018 15:10:18 -0600 Subject: [PATCH] Add symlinkFile to the public AppDir interface (#42) * Add symlinkFile to the public AppDir interface * Rename AppDir::symlinkFile to AppDir::createSymlink * change return value to bool * Remove duplicated header * Remove blank lines * Add comment * Fix test name * Change createSymlink signature. Name changed to createRelativeSymlink and remove the useRelativePath argument * Remove commented tests. --- include/linuxdeploy/core/appdir.h | 3 +++ src/core/appdir.cpp | 5 +++++ tests/core/test_appdir.cpp | 14 ++++++++++++++ 3 files changed, 22 insertions(+) diff --git a/include/linuxdeploy/core/appdir.h b/include/linuxdeploy/core/appdir.h index 3c6069c..22ecf74 100644 --- a/include/linuxdeploy/core/appdir.h +++ b/include/linuxdeploy/core/appdir.h @@ -61,6 +61,9 @@ namespace linuxdeploy { // deploy arbitrary file void deployFile(const boost::filesystem::path& from, const boost::filesystem::path& to); + // create an relative symlink to at . + bool createRelativeSymlink(const boost::filesystem::path& target, const boost::filesystem::path& symlink); + // execute deferred copy operations bool executeDeferredOperations(); diff --git a/src/core/appdir.cpp b/src/core/appdir.cpp index 195f4a8..9ec4582 100644 --- a/src/core/appdir.cpp +++ b/src/core/appdir.cpp @@ -9,6 +9,7 @@ #include #include + // local headers #include "linuxdeploy/core/appdir.h" #include "linuxdeploy/core/elf.h" @@ -774,6 +775,10 @@ namespace linuxdeploy { return d->deployFile(from, to, true); } + bool AppDir::createRelativeSymlink(const bf::path& target, const bf::path& symlink) { + d->symlinkFile(target, symlink, true); + } + std::vector AppDir::listExecutables() { std::vector executables; diff --git a/tests/core/test_appdir.cpp b/tests/core/test_appdir.cpp index 39d9b00..e93b683 100644 --- a/tests/core/test_appdir.cpp +++ b/tests/core/test_appdir.cpp @@ -121,6 +121,20 @@ namespace AppDirTest { ASSERT_TRUE(is_regular_file(destination)); } + + TEST_F(AppDirUnitTestsFixture, createSymlink) { + auto destination = tmpAppDir / "usr/share/doc/simple_application/test123"; + appDir.deployFile(SIMPLE_FILE_PATH, destination); + appDir.executeDeferredOperations(); + + ASSERT_TRUE(is_regular_file(destination)); + + appDir.createRelativeSymlink(destination, tmpAppDir / "relative_link"); + + auto res = read_symlink(tmpAppDir / "relative_link"); + auto expected = relative(destination, tmpAppDir); + ASSERT_TRUE(res == expected); + } } int main(int argc, char **argv) {