diff options
| author | LRFLEW <LRFLEW@aol.com> | 2018-10-17 12:46:27 -0600 |
|---|---|---|
| committer | Robert Schumacher <roschuma@microsoft.com> | 2018-10-17 11:46:27 -0700 |
| commit | 3d12e5ca72d948121463beec6e48290877684471 (patch) | |
| tree | 74d1edb1de757c0d0ce7adbaa99e376bc4adb336 | |
| parent | e7a37f14a82aaead89447c029f62c3427e07373c (diff) | |
| download | vcpkg-3d12e5ca72d948121463beec6e48290877684471.tar.gz vcpkg-3d12e5ca72d948121463beec6e48290877684471.zip | |
Handle symlink when installing or removing a library (#4479)
| -rw-r--r-- | toolsrc/include/vcpkg/base/files.h | 3 | ||||
| -rw-r--r-- | toolsrc/src/vcpkg/base/files.cpp | 8 | ||||
| -rw-r--r-- | toolsrc/src/vcpkg/install.cpp | 19 | ||||
| -rw-r--r-- | toolsrc/src/vcpkg/remove.cpp | 4 |
4 files changed, 31 insertions, 3 deletions
diff --git a/toolsrc/include/vcpkg/base/files.h b/toolsrc/include/vcpkg/base/files.h index ed12ffd74..b07ff25b3 100644 --- a/toolsrc/include/vcpkg/base/files.h +++ b/toolsrc/include/vcpkg/base/files.h @@ -20,6 +20,7 @@ namespace fs inline bool is_regular_file(file_status s) { return stdfs::is_regular_file(s); } inline bool is_directory(file_status s) { return stdfs::is_directory(s); } + inline bool is_symlink(file_status s) { return stdfs::is_symlink(s); } } namespace vcpkg::Files @@ -54,7 +55,9 @@ namespace vcpkg::Files const fs::path& newpath, fs::copy_options opts, std::error_code& ec) = 0; + virtual void copy_symlink(const fs::path& oldpath, const fs::path& newpath, std::error_code& ec) = 0; virtual fs::file_status status(const fs::path& path, std::error_code& ec) const = 0; + virtual fs::file_status symlink_status(const fs::path& path, std::error_code& ec) const = 0; virtual std::vector<fs::path> find_from_PATH(const std::string& name) const = 0; diff --git a/toolsrc/src/vcpkg/base/files.cpp b/toolsrc/src/vcpkg/base/files.cpp index 4ff0912d1..f9bce8631 100644 --- a/toolsrc/src/vcpkg/base/files.cpp +++ b/toolsrc/src/vcpkg/base/files.cpp @@ -216,11 +216,19 @@ namespace vcpkg::Files { return fs::stdfs::copy_file(oldpath, newpath, opts, ec); } + virtual void copy_symlink(const fs::path& oldpath, const fs::path& newpath, std::error_code& ec) + { + return fs::stdfs::copy_symlink(oldpath, newpath, ec); + } virtual fs::file_status status(const fs::path& path, std::error_code& ec) const override { return fs::stdfs::status(path, ec); } + virtual fs::file_status symlink_status(const fs::path& path, std::error_code& ec) const override + { + return fs::stdfs::symlink_status(path, ec); + } virtual void write_contents(const fs::path& file_path, const std::string& data, std::error_code& ec) override { ec.clear(); diff --git a/toolsrc/src/vcpkg/install.cpp b/toolsrc/src/vcpkg/install.cpp index 4bb84831e..1cfa2bf71 100644 --- a/toolsrc/src/vcpkg/install.cpp +++ b/toolsrc/src/vcpkg/install.cpp @@ -62,7 +62,7 @@ namespace vcpkg::Install auto files = fs.get_files_recursive(source_dir); for (auto&& file : files) { - const auto status = fs.status(file, ec); + const auto status = fs.symlink_status(file, ec); if (ec) { System::println(System::Color::error, "failed: %s: %s", file.u8string(), ec.message()); @@ -111,6 +111,23 @@ namespace vcpkg::Install output.push_back(Strings::format(R"(%s/%s)", destination_subdirectory, suffix)); break; } + case fs::file_type::symlink: + { + if (fs.exists(target)) + { + System::println(System::Color::warning, + "File %s was already present and will be overwritten", + target.u8string(), + ec.message()); + } + fs.copy_symlink(file, target, ec); + if (ec) + { + System::println(System::Color::error, "failed: %s: %s", target.u8string(), ec.message()); + } + output.push_back(Strings::format(R"(%s/%s)", destination_subdirectory, suffix)); + break; + } default: System::println(System::Color::error, "failed: %s: cannot handle file type", file.u8string()); break; diff --git a/toolsrc/src/vcpkg/remove.cpp b/toolsrc/src/vcpkg/remove.cpp index 13cc9325e..921a04c23 100644 --- a/toolsrc/src/vcpkg/remove.cpp +++ b/toolsrc/src/vcpkg/remove.cpp @@ -55,7 +55,7 @@ namespace vcpkg::Remove auto target = paths.installed / suffix; - const auto status = fs.status(target, ec); + const auto status = fs.symlink_status(target, ec); if (ec) { System::println(System::Color::error, "failed: status(%s): %s", target.u8string(), ec.message()); @@ -66,7 +66,7 @@ namespace vcpkg::Remove { dirs_touched.push_back(target); } - else if (fs::is_regular_file(status)) + else if (fs::is_regular_file(status) || fs::is_symlink(status)) { fs.remove(target, ec); if (ec) |
