aboutsummaryrefslogtreecommitdiff
path: root/toolsrc/include
diff options
context:
space:
mode:
authorRobert Schumacher <roschuma@microsoft.com>2019-06-19 11:49:57 -0700
committerGitHub <noreply@github.com>2019-06-19 11:49:57 -0700
commite5b92a39116791cfd4e1f4931221c9f69125bae3 (patch)
tree6f868340680f87b5e673688ffcdae8ea8351c8ea /toolsrc/include
parentdf0b8d9e55bfb6772a9e5c02fd826ab520e5d2f8 (diff)
downloadvcpkg-e5b92a39116791cfd4e1f4931221c9f69125bae3.tar.gz
vcpkg-e5b92a39116791cfd4e1f4931221c9f69125bae3.zip
[vcpkg] Improve vcpkg::Files::Filesystem error handling (#6919)
* [vcpkg] Modify Filesystem::remove and Filesystem::rename to not throw. * [.gitignore] Ignore new VS2019 CMake integration default location * [.gitignore] Ignore CMakeSettings.json in toolsrc * [vcpkg] Time external processes called with System::cmd_execute * [vcpkg] Work around VS2019 CMake bug * [vcpkg] Fix several unused variable warnings. * [vcpkg] Improve error handling in vcpkg::Files::Filesystem Always require either std::error_code or LineInfo to print better errors. * [vcpkg] Fixup missing return value. Drive by fix: silence warnings in tests. * [vcpkg] Fix exiting in error_code overload Drive by fixes for /analyze with VS2019
Diffstat (limited to 'toolsrc/include')
-rw-r--r--toolsrc/include/tests.utils.h8
-rw-r--r--toolsrc/include/vcpkg/base/files.h14
-rw-r--r--toolsrc/include/vcpkg/base/graphs.h4
-rw-r--r--toolsrc/include/vcpkg/base/optional.h23
-rw-r--r--toolsrc/include/vcpkg/base/strings.h2
5 files changed, 34 insertions, 17 deletions
diff --git a/toolsrc/include/tests.utils.h b/toolsrc/include/tests.utils.h
index 7f7ec9e88..3e8514e67 100644
--- a/toolsrc/include/tests.utils.h
+++ b/toolsrc/include/tests.utils.h
@@ -13,7 +13,7 @@
namespace Microsoft::VisualStudio::CppUnitTestFramework
{
template<>
- std::wstring ToString<vcpkg::Dependencies::InstallPlanType>(const vcpkg::Dependencies::InstallPlanType& t)
+ inline std::wstring ToString<vcpkg::Dependencies::InstallPlanType>(const vcpkg::Dependencies::InstallPlanType& t)
{
switch (t)
{
@@ -26,7 +26,7 @@ namespace Microsoft::VisualStudio::CppUnitTestFramework
}
template<>
- std::wstring ToString<vcpkg::Dependencies::RequestType>(const vcpkg::Dependencies::RequestType& t)
+ inline std::wstring ToString<vcpkg::Dependencies::RequestType>(const vcpkg::Dependencies::RequestType& t)
{
switch (t)
{
@@ -38,13 +38,13 @@ namespace Microsoft::VisualStudio::CppUnitTestFramework
}
template<>
- std::wstring ToString<vcpkg::PackageSpecParseResult>(const vcpkg::PackageSpecParseResult& t)
+ inline std::wstring ToString<vcpkg::PackageSpecParseResult>(const vcpkg::PackageSpecParseResult& t)
{
return ToString(static_cast<uint32_t>(t));
}
template<>
- std::wstring ToString<vcpkg::PackageSpec>(const vcpkg::PackageSpec& t)
+ inline std::wstring ToString<vcpkg::PackageSpec>(const vcpkg::PackageSpec& t)
{
return ToString(t.to_string());
}
diff --git a/toolsrc/include/vcpkg/base/files.h b/toolsrc/include/vcpkg/base/files.h
index b07ff25b3..02e2b8db8 100644
--- a/toolsrc/include/vcpkg/base/files.h
+++ b/toolsrc/include/vcpkg/base/files.h
@@ -27,21 +27,25 @@ namespace vcpkg::Files
{
struct Filesystem
{
+ std::string read_contents(const fs::path& file_path, LineInfo linfo) const;
virtual Expected<std::string> read_contents(const fs::path& file_path) const = 0;
virtual Expected<std::vector<std::string>> read_lines(const fs::path& file_path) const = 0;
virtual fs::path find_file_recursively_up(const fs::path& starting_dir, const std::string& filename) const = 0;
virtual std::vector<fs::path> get_files_recursive(const fs::path& dir) const = 0;
virtual std::vector<fs::path> get_files_non_recursive(const fs::path& dir) const = 0;
-
- virtual void write_lines(const fs::path& file_path, const std::vector<std::string>& lines) = 0;
+ void write_lines(const fs::path& file_path, const std::vector<std::string>& lines, LineInfo linfo);
+ virtual void write_lines(const fs::path& file_path,
+ const std::vector<std::string>& lines,
+ std::error_code& ec) = 0;
+ void write_contents(const fs::path& path, const std::string& data, LineInfo linfo);
virtual void write_contents(const fs::path& file_path, const std::string& data, std::error_code& ec) = 0;
- virtual void rename(const fs::path& oldpath, const fs::path& newpath) = 0;
+ void rename(const fs::path& oldpath, const fs::path& newpath, LineInfo linfo);
virtual void rename(const fs::path& oldpath, const fs::path& newpath, std::error_code& ec) = 0;
virtual void rename_or_copy(const fs::path& oldpath,
const fs::path& newpath,
StringLiteral temp_suffix,
std::error_code& ec) = 0;
- virtual bool remove(const fs::path& path) = 0;
+ bool remove(const fs::path& path, LineInfo linfo);
virtual bool remove(const fs::path& path, std::error_code& ec) = 0;
virtual std::uintmax_t remove_all(const fs::path& path, std::error_code& ec) = 0;
virtual bool exists(const fs::path& path) const = 0;
@@ -60,8 +64,6 @@ namespace vcpkg::Files
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;
-
- void write_contents(const fs::path& file_path, const std::string& data);
};
Filesystem& get_real_filesystem();
diff --git a/toolsrc/include/vcpkg/base/graphs.h b/toolsrc/include/vcpkg/base/graphs.h
index 46831a911..9901a49a0 100644
--- a/toolsrc/include/vcpkg/base/graphs.h
+++ b/toolsrc/include/vcpkg/base/graphs.h
@@ -44,9 +44,9 @@ namespace vcpkg::Graphs
void shuffle(Container& c, Randomizer* r)
{
if (!r) return;
- for (int i = static_cast<int>(c.size()); i > 1; --i)
+ for (auto i = c.size(); i > 1; --i)
{
- auto j = r->random(i);
+ auto j = r->random(static_cast<int>(i));
if (j != i - 1)
{
std::swap(c[i - 1], c[j]);
diff --git a/toolsrc/include/vcpkg/base/optional.h b/toolsrc/include/vcpkg/base/optional.h
index 4d386a961..2d8c126c6 100644
--- a/toolsrc/include/vcpkg/base/optional.h
+++ b/toolsrc/include/vcpkg/base/optional.h
@@ -19,6 +19,9 @@ namespace vcpkg
template<class T, bool B = std::is_copy_constructible<T>::value>
struct OptionalStorage
{
+#if defined(_WIN32)
+#pragma warning(suppress : 26495)
+#endif
constexpr OptionalStorage() noexcept : m_is_present(false), m_inactive() {}
constexpr OptionalStorage(const T& t) : m_is_present(true), m_t(t) {}
constexpr OptionalStorage(T&& t) : m_is_present(true), m_t(std::move(t)) {}
@@ -28,12 +31,18 @@ namespace vcpkg
if (m_is_present) m_t.~T();
}
+#if defined(_WIN32)
+#pragma warning(suppress : 26495)
+#endif
OptionalStorage(const OptionalStorage& o) : m_is_present(o.m_is_present), m_inactive()
{
if (m_is_present) new (&m_t) T(o.m_t);
}
- OptionalStorage(OptionalStorage&& o) : m_is_present(o.m_is_present), m_inactive()
+#if defined(_WIN32)
+#pragma warning(suppress : 26495)
+#endif
+ OptionalStorage(OptionalStorage&& o) noexcept : m_is_present(o.m_is_present), m_inactive()
{
if (m_is_present)
{
@@ -59,7 +68,7 @@ namespace vcpkg
return *this;
}
- OptionalStorage& operator=(OptionalStorage&& o)
+ OptionalStorage& operator=(OptionalStorage&& o) noexcept
{
if (m_is_present && o.m_is_present)
{
@@ -100,6 +109,9 @@ namespace vcpkg
template<class T>
struct OptionalStorage<T, false>
{
+#if defined(_WIN32)
+#pragma warning(suppress : 26495)
+#endif
constexpr OptionalStorage() noexcept : m_is_present(false), m_inactive() {}
constexpr OptionalStorage(T&& t) : m_is_present(true), m_t(std::move(t)) {}
@@ -108,7 +120,10 @@ namespace vcpkg
if (m_is_present) m_t.~T();
}
- OptionalStorage(OptionalStorage&& o) : m_is_present(o.m_is_present), m_inactive()
+#if defined(_WIN32)
+#pragma warning(suppress : 26495)
+#endif
+ OptionalStorage(OptionalStorage&& o) noexcept : m_is_present(o.m_is_present), m_inactive()
{
if (m_is_present)
{
@@ -116,7 +131,7 @@ namespace vcpkg
}
}
- OptionalStorage& operator=(OptionalStorage&& o)
+ OptionalStorage& operator=(OptionalStorage&& o) noexcept
{
if (m_is_present && o.m_is_present)
{
diff --git a/toolsrc/include/vcpkg/base/strings.h b/toolsrc/include/vcpkg/base/strings.h
index 3a9de97df..d553d1d41 100644
--- a/toolsrc/include/vcpkg/base/strings.h
+++ b/toolsrc/include/vcpkg/base/strings.h
@@ -163,7 +163,7 @@ namespace vcpkg::Strings
std::vector<std::string> split(const std::string& s, const std::string& delimiter);
- std::vector<std::string> split(const std::string& s, const std::string& delimiter, int max_count);
+ std::vector<std::string> split(const std::string& s, const std::string& delimiter, size_t max_count);
std::vector<StringView> find_all_enclosed(StringView input, StringView left_delim, StringView right_delim);