aboutsummaryrefslogtreecommitdiff
path: root/toolsrc/src
diff options
context:
space:
mode:
authorNicole Mazzuca <t-nimaz@microsoft.com>2019-07-15 18:51:03 -0700
committerNicole Mazzuca <t-nimaz@microsoft.com>2019-07-15 18:51:03 -0700
commit65d34c5e55ef30a6572dfb3b79d212196fbadc0d (patch)
tree87cf2bf14e22ab68cc622eb7f8bd9e030cac106b /toolsrc/src
parent02c977186e890e4090d91c171b42d20729e668af (diff)
downloadvcpkg-65d34c5e55ef30a6572dfb3b79d212196fbadc0d.tar.gz
vcpkg-65d34c5e55ef30a6572dfb3b79d212196fbadc0d.zip
wheeeee more fixes
Diffstat (limited to 'toolsrc/src')
-rw-r--r--toolsrc/src/tests.files.cpp64
-rw-r--r--toolsrc/src/tests.strings.cpp20
-rw-r--r--toolsrc/src/vcpkg/base/files.cpp2
-rw-r--r--toolsrc/src/vcpkg/base/strings.cpp23
4 files changed, 59 insertions, 50 deletions
diff --git a/toolsrc/src/tests.files.cpp b/toolsrc/src/tests.files.cpp
index c99dbb286..56b0ceac6 100644
--- a/toolsrc/src/tests.files.cpp
+++ b/toolsrc/src/tests.files.cpp
@@ -4,6 +4,7 @@
#include <vcpkg/base/strings.h>
#include <iostream>
+#include <filesystem> // required for filesystem::create_{directory_}symlink
#include <random>
#include <windows.h>
@@ -21,18 +22,20 @@ namespace UnitTest1
{
HKEY key;
const auto status = RegOpenKeyExW(
- HKEY_LOCAL_MACHINE, LR"(SOFTWARE\Microsoft\Windows\CurrentVersion\AppModelUnlock)", 0, KEY_READ, &key);
+ HKEY_LOCAL_MACHINE, LR"(SOFTWARE\Microsoft\Windows\CurrentVersion\AppModelUnlock)", 0, 0, &key);
- if (!status)
+ if (status == ERROR_FILE_NOT_FOUND)
{
ALLOW_SYMLINKS = false;
std::clog << "Symlinks are not allowed on this system\n";
}
else
{
+ // if we get a permissions error, we still know that we're in developer mode
ALLOW_SYMLINKS = true;
- RegCloseKey(key);
}
+
+ if (status == ERROR_SUCCESS) RegCloseKey(key);
}
private:
@@ -62,9 +65,9 @@ namespace UnitTest1
std::clog << "temp dir is: " << temp_dir << '\n';
- std::error_code ec;
create_directory_tree(urbg, fs, 0, temp_dir);
+ std::error_code ec;
fs::path fp;
fs.remove_all(temp_dir, ec, fp);
Assert::IsFalse(bool(ec));
@@ -80,7 +83,7 @@ namespace UnitTest1
return std::mt19937_64{index + 9223372036854775837};
}
- std::string get_random_filename(std::mt19937_64& urbg) { return vcpkg::Strings::b64url_encode(uid{}(urbg)); }
+ std::string get_random_filename(std::mt19937_64& urbg) { return vcpkg::Strings::b32_encode(uid{}(urbg)); }
void create_directory_tree(std::mt19937_64& urbg,
vcpkg::Files::Filesystem& fs,
@@ -88,46 +91,57 @@ namespace UnitTest1
const fs::path& base)
{
std::random_device rd;
- constexpr auto max_depth = std::uint64_t(3);
- const auto width = depth ? uid{0, (max_depth - depth) * 3 / 2}(urbg) : 5;
+ constexpr std::uint64_t max_depth = 5;
+ constexpr std::uint64_t width = 5;
+ const auto type = depth < max_depth ? uid{0, 9}(urbg) : uid{7, 9}(urbg);
+
+ // 0 <= type < 7 : directory
+ // 7 = type : regular
+ // 8 = type : regular symlink (regular file if !ALLOW_SYMLINKS)
+ // 9 = type : directory symlink (^^)
std::error_code ec;
- if (width == 0)
+ if (type >= 7)
{
// I don't want to move urbg forward conditionally
- const auto type = uid{0, 3}(urbg);
- if (type == 0 || !ALLOW_SYMLINKS)
+ if (type == 7 || !ALLOW_SYMLINKS)
{
- // 0 is a regular file
+ // regular file
fs.write_contents(base, "", ec);
}
- else if (type == 1)
+ else if (type == 8)
{
- // 1 is a regular symlink
+ // regular symlink
fs.write_contents(base, "", ec);
Assert::IsFalse(bool(ec));
- fs::path base_link = base;
- base_link.append("-link");
- fs::stdfs::create_symlink(base, base_link, ec);
+ const std::filesystem::path basep = base.native();
+ auto basep_link = basep;
+ basep_link.replace_filename(basep.filename().native() + L"-link");
+ std::filesystem::create_symlink(basep, basep_link, ec);
}
else
{
- // 2 is a directory symlink
- fs::stdfs::create_directory_symlink(".", base, ec);
+ // directory symlink
+ std::filesystem::path basep = base.native();
+ std::filesystem::create_directory_symlink(basep / "..", basep, ec);
}
Assert::IsFalse(bool(ec));
- return;
}
-
- fs.create_directory(base, ec);
- Assert::IsFalse(bool(ec));
-
- for (int i = 0; i < width; ++i)
+ else
{
- create_directory_tree(urbg, fs, depth + 1, base / get_random_filename(urbg));
+ // directory
+ fs.create_directory(base, ec);
+ Assert::IsFalse(bool(ec));
+
+ for (int i = 0; i < width; ++i)
+ {
+ create_directory_tree(urbg, fs, depth + 1, base / get_random_filename(urbg));
+ }
+
}
+
}
};
}
diff --git a/toolsrc/src/tests.strings.cpp b/toolsrc/src/tests.strings.cpp
index 14b449e86..6301ea05d 100644
--- a/toolsrc/src/tests.strings.cpp
+++ b/toolsrc/src/tests.strings.cpp
@@ -16,21 +16,21 @@ namespace UnitTest1 {
std::vector<std::pair<std::uint64_t, std::string>> map;
- map.emplace_back(0, "AAAAAAAAAAA");
- map.emplace_back(1, "BAAAAAAAAAA");
+ map.emplace_back(0, "AAAAAAAAAAAAA");
+ map.emplace_back(1, "BAAAAAAAAAAAA");
- map.emplace_back(u64(1) << 32, "AAAAAEAAAAA");
- map.emplace_back((u64(1) << 32) + 1, "BAAAAEAAAAA");
+ map.emplace_back(u64(1) << 32, "AAAAAAEAAAAAA");
+ map.emplace_back((u64(1) << 32) + 1, "BAAAAAEAAAAAA");
- map.emplace_back(0xE4D0'1065'D11E'0229, "pIgHRXGEQTO");
- map.emplace_back(0xA626'FE45'B135'07FF, "_fQNxWk_mYK");
- map.emplace_back(0xEE36'D228'0C31'D405, "FQdMMgi024O");
- map.emplace_back(0x1405'64E7'FE7E'A88C, "Miqf-fOZFQB");
- map.emplace_back(0xFFFF'FFFF'FFFF'FFFF, "__________P");
+ map.emplace_back(0xE4D0'1065'D11E'0229, "JRA4RIXMQAUJO");
+ map.emplace_back(0xA626'FE45'B135'07FF, "77BKTYWI6XJMK");
+ map.emplace_back(0xEE36'D228'0C31'D405, "FAVDDGAFSWN4O");
+ map.emplace_back(0x1405'64E7'FE7E'A88C, "MEK5H774ELBIB");
+ map.emplace_back(0xFFFF'FFFF'FFFF'FFFF, "777777777777P");
std::string result;
for (const auto& pr : map) {
- result = vcpkg::Strings::b64url_encode(pr.first);
+ result = vcpkg::Strings::b32_encode(pr.first);
Assert::AreEqual(result, pr.second);
}
}
diff --git a/toolsrc/src/vcpkg/base/files.cpp b/toolsrc/src/vcpkg/base/files.cpp
index e40822705..6c6945e44 100644
--- a/toolsrc/src/vcpkg/base/files.cpp
+++ b/toolsrc/src/vcpkg/base/files.cpp
@@ -423,7 +423,7 @@ namespace vcpkg::Files
{
std::error_code ec;
- const auto tmp_name = Strings::b64url_encode(info.index++);
+ const auto tmp_name = Strings::b32_encode(info.index++);
const auto tmp_path = info.tmp_directory / tmp_name;
fs::stdfs::rename(current_path, tmp_path, ec);
diff --git a/toolsrc/src/vcpkg/base/strings.cpp b/toolsrc/src/vcpkg/base/strings.cpp
index ade4384a9..7970e1b46 100644
--- a/toolsrc/src/vcpkg/base/strings.cpp
+++ b/toolsrc/src/vcpkg/base/strings.cpp
@@ -294,26 +294,21 @@ namespace vcpkg::Strings
namespace
{
template<class Integral>
- std::string b64url_encode_implementation(Integral x)
+ std::string b32_encode_implementation(Integral x)
{
static_assert(std::is_integral<Integral>::value, "b64url_encode must take an integer type");
using Unsigned = std::make_unsigned_t<Integral>;
auto value = static_cast<Unsigned>(x);
- // 64 values, plus the implicit \0
- constexpr static char map[65] =
- /* 0123456789ABCDEF */
- /*0*/ "ABCDEFGHIJKLMNOP"
- /*1*/ "QRSTUVWXYZabcdef"
- /*2*/ "ghijklmnopqrstuv"
- /*3*/ "wxyz0123456789-_";
+ // 32 values, plus the implicit \0
+ constexpr static char map[33] = "ABCDEFGHIJKLMNOP" "QRSTUVWXYZ234567";
- // log2(64)
- constexpr static int shift = 6;
- // 64 - 1
- constexpr static auto mask = 63;
+ // log2(32)
+ constexpr static int shift = 5;
+ // 32 - 1
+ constexpr static auto mask = 31;
- // ceiling(bitsize(Integral) / log2(64))
+ // ceiling(bitsize(Integral) / log2(32))
constexpr static auto result_size = (sizeof(value) * 8 + shift - 1) / shift;
std::string result;
@@ -329,6 +324,6 @@ namespace vcpkg::Strings
}
}
- std::string b64url_encode(std::uint64_t x) noexcept { return b64url_encode_implementation(x); }
+ std::string b32_encode(std::uint64_t x) noexcept { return b32_encode_implementation(x); }
}