diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index 17c0202e..c4f6ef23 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -20,14 +20,13 @@ jobs: run: sudo apt-get install fuse libfuse-dev - name: vcpkg build id: vcpkg - uses: johnwason/vcpkg-action@v4 + uses: johnwason/vcpkg-action@v6 with: manifest-dir: ${{ github.workspace }} triplet: x64-linux token: ${{ github.token }} + github-binarycache: true - name: build-test - env: - VCPKG_DEFAULT_BINARY_CACHE: ${{ github.workspace }}/vcpkg_cache run: python3 build.py --enable_unit_test --enable_integration_test --vcpkg_root=${{ github.workspace }}/vcpkg --build_root=./build - name: upload uses: actions/upload-artifact@v1 @@ -46,7 +45,7 @@ jobs: with: python-version: "3.x" - name: install - run: sudo apt-get install fuse libfuse-dev libcrypto++-dev libargon2-dev libtclap-dev libabsl-dev libutf8proc-dev libjsoncpp-dev doctest-dev + run: sudo apt-get install fuse libfuse-dev libcrypto++-dev libargon2-dev libtclap-dev libabsl-dev libutf8proc-dev libjsoncpp-dev doctest-dev libsqlite3-dev - name: configure run: mkdir build && cd build && cmake -DCMAKE_BUILD_TYPE=Release -DSECUREFS_USE_VCPKG=OFF .. - name: build @@ -69,15 +68,15 @@ jobs: - name: install run: brew install macfuse - name: vcpkg build - uses: johnwason/vcpkg-action@v4 + uses: johnwason/vcpkg-action@v6 id: vcpkg with: manifest-dir: ${{ github.workspace }} triplet: x64-osx token: ${{ github.token }} + cache-key: macos-11-x64 + github-binarycache: true - name: build - env: - VCPKG_DEFAULT_BINARY_CACHE: ${{ github.workspace }}/vcpkg_cache run: python3 build.py --enable_unit_test --vcpkg_root=${{ github.workspace }}/vcpkg --triplet=x64-osx --build_root=./build - name: upload uses: actions/upload-artifact@v1 @@ -100,15 +99,15 @@ jobs: - name: install run: brew install macfuse - name: vcpkg build - uses: johnwason/vcpkg-action@v4 + uses: johnwason/vcpkg-action@v6 id: vcpkg with: manifest-dir: ${{ github.workspace }} triplet: arm64-osx token: ${{ github.token }} + cache-key: macos-11-arm64 + github-binarycache: true - name: build - env: - VCPKG_DEFAULT_BINARY_CACHE: ${{ github.workspace }}/vcpkg_cache run: python3 build.py --vcpkg_root=${{ github.workspace }}/vcpkg --triplet=arm64-osx --build_root=./build --cmake_defines CMAKE_OSX_ARCHITECTURES=arm64 - name: upload uses: actions/upload-artifact@v1 @@ -129,16 +128,15 @@ jobs: - name: install run: choco install winfsp - name: vcpkg build - uses: johnwason/vcpkg-action@v4 + uses: johnwason/vcpkg-action@v6 id: vcpkg with: manifest-dir: ${{ github.workspace }} triplet: x64-windows-static-md token: ${{ github.token }} cache-key: windows + github-binarycache: true - name: build-test - env: - VCPKG_DEFAULT_BINARY_CACHE: ${{ github.workspace }}/vcpkg_cache run: python3 build.py --enable_unit_test --enable_integration_test --vcpkg_root=${{ github.workspace }}/vcpkg --triplet=x64-windows-static-md --build_root=./build - name: upload uses: actions/upload-artifact@v1 diff --git a/CMakeLists.txt b/CMakeLists.txt index e6208bb3..94cf1351 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -74,8 +74,14 @@ find_path(TCLAP_INCLUDE_DIRS "tclap/Arg.h") target_include_directories(securefs-static PUBLIC ${TCLAP_INCLUDE_DIRS}) find_package(absl CONFIG REQUIRED) target_link_libraries( - securefs-static PUBLIC absl::base absl::inlined_vector absl::flat_hash_map - absl::strings absl::optional) + securefs-static + PUBLIC absl::base + absl::inlined_vector + absl::flat_hash_map + absl::strings + absl::optional + absl::str_format + absl::span) if(SECUREFS_USE_VCPKG) find_package(cryptopp CONFIG REQUIRED) diff --git a/sources/commands.cpp b/sources/commands.cpp index a1b9269b..4956dcee 100644 --- a/sources/commands.cpp +++ b/sources/commands.cpp @@ -8,6 +8,7 @@ #include "platform.h" #include "win_get_proc.h" +#include #include #include #include @@ -1400,7 +1401,7 @@ class MountCommand : public _SinglePasswordCommandBase auto rc = fsopt.root->listxattr(".", nullptr, 0); if (rc < 0) { - absl::FPrintf(stderr, + absl::FPrintF(stderr, "Warning: %s has no extended attribute support.\nXattr is disabled\n", data_dir.getValue()); native_xattr = false; diff --git a/sources/common_platform.cpp b/sources/common_platform.cpp index 663dcfdb..2cf6da59 100644 --- a/sources/common_platform.cpp +++ b/sources/common_platform.cpp @@ -10,7 +10,7 @@ const OSService& OSService::get_default() return service; } -std::string OSService::temp_name(const std::string& prefix, const std::string& suffix) +std::string OSService::temp_name(absl::string_view prefix, absl::string_view suffix) { byte random[16]; generate_random(random, array_length(random)); diff --git a/sources/platform.h b/sources/platform.h index acf6d520..c64af2d0 100644 --- a/sources/platform.h +++ b/sources/platform.h @@ -165,9 +165,9 @@ class OSService std::string m_dir_name; public: - static bool is_absolute(const std::string& path); - static native_string_type concat_and_norm(const std::string& base_dir, const std::string& path); - native_string_type norm_path(const std::string& path) const + static bool is_absolute(absl::string_view path); + static native_string_type concat_and_norm(absl::string_view base_dir, absl::string_view path); + native_string_type norm_path(absl::string_view path) const { return concat_and_norm(m_dir_name, path); } @@ -220,7 +220,7 @@ class OSService static uint32_t getgid() noexcept; static int64_t raise_fd_limit() noexcept; - static std::string temp_name(const std::string& prefix, const std::string& suffix); + static std::string temp_name(absl::string_view prefix, absl::string_view suffix); static const OSService& get_default(); static void get_current_time(fuse_timespec& out); static void get_current_time_in_tm(struct tm* tm, int* nanoseconds); diff --git a/sources/unix.cpp b/sources/unix.cpp index 47346ad7..394aa658 100644 --- a/sources/unix.cpp +++ b/sources/unix.cpp @@ -6,6 +6,8 @@ #include "platform.h" #include "streams.h" +#include +#include #include #include @@ -242,21 +244,21 @@ class UnixDirectoryTraverser : public DirectoryTraverser void rewind() override { ::rewinddir(m_dir); } }; -bool OSService::is_absolute(const std::string& path) { return path.size() > 0 && path[0] == '/'; } +bool OSService::is_absolute(absl::string_view path) { return path.size() > 0 && path[0] == '/'; } -native_string_type OSService::concat_and_norm(const std::string& base_dir, const std::string& path) +native_string_type OSService::concat_and_norm(absl::string_view base_dir, absl::string_view path) { if (base_dir.empty() || is_absolute(path)) - return path.to_string(); + return {path.data(), path.size()}; if (!is_absolute(base_dir)) { - throwInvalidArgumentException("base_dir must be absolute, but is " + base_dir); + throwInvalidArgumentException(absl::StrCat("base_dir must be absolute, but is ", base_dir)); } - if (base_dir.ends_with("/")) + if (base_dir.size() > 0 && base_dir.back() == '/') { - return base_dir + path; + return absl::StrCat(base_dir, path); } - return base_dir + "/" + path; + return absl::StrCat(base_dir, "/", path); } OSService::OSService() { m_dir_fd = AT_FDCWD; } diff --git a/sources/win.cpp b/sources/win.cpp index d5342f4f..89715d5a 100644 --- a/sources/win.cpp +++ b/sources/win.cpp @@ -712,81 +712,67 @@ OSService::OSService() : m_root_handle(INVALID_HANDLE_VALUE) {} OSService::~OSService() { CloseHandle(m_root_handle); } -static bool is_absolute_path(absl::string_view path) +bool OSService::is_absolute(absl::string_view path) { return path.empty() || path[0] == '/' || path[0] == '\\' || (path.size() >= 2 && path[1] == ':'); } -bool OSService::is_absolute(const std::string& path) +native_string_type OSService::concat_and_norm(absl::string_view base_dir, absl::string_view path) { - return is_absolute_path(absl::string_view(path.data(), path.size())); -} - -namespace -{ - native_string_type concat_and_norm_path(absl::string_view base_dir, absl::string_view path) + if (base_dir.empty() || is_absolute(path)) { - if (base_dir.empty() || is_absolute_path(path)) - { - return widen_string(path); - } - if (!is_absolute_path(base_dir)) - { - throwInvalidArgumentException( - absl::StrCat("base_dir must be an absolute path, yet we received ", base_dir)); - } - std::vector buffer; - buffer.reserve(2 * (base_dir.size() + path.size()) + 15); - buffer.insert(buffer.end(), base_dir.begin(), base_dir.end()); - buffer.push_back('\\'); - buffer.insert(buffer.end(), path.begin(), path.end()); - - absl::InlinedVector pieces; - for (absl::string_view p : - absl::StrSplit(absl::string_view(buffer.data(), buffer.size()), - absl::ByAnyChar("/\\"), - [](absl::string_view p) { return !p.empty() && p != "."; })) + return widen_string(path); + } + if (!is_absolute(base_dir)) + { + throwInvalidArgumentException( + absl::StrCat("base_dir must be an absolute path, yet we received ", base_dir)); + } + std::vector buffer; + buffer.reserve(2 * (base_dir.size() + path.size()) + 15); + buffer.insert(buffer.end(), base_dir.begin(), base_dir.end()); + buffer.push_back('\\'); + buffer.insert(buffer.end(), path.begin(), path.end()); + + absl::InlinedVector pieces; + for (absl::string_view p : + absl::StrSplit(absl::string_view(buffer.data(), buffer.size()), + absl::ByAnyChar("/\\"), + [](absl::string_view p) { return !p.empty() && p != "."; })) + { + if (p == "..") { - if (p == "..") + if (!pieces.empty()) { - if (!pieces.empty()) - { - pieces.pop_back(); - } - } - else - { - pieces.push_back(p); + pieces.pop_back(); } } - size_t offset = buffer.size(); - - static constexpr absl::string_view LONG_PATH_PREFIX = R"(\\)"; - - if (!absl::StartsWith(base_dir, LONG_PATH_PREFIX)) - { - buffer.push_back('\\'); - buffer.push_back('\\'); - buffer.push_back('?'); - } else { - buffer.push_back('\\'); + pieces.push_back(p); } - for (absl::string_view p : pieces) - { - buffer.push_back('\\'); - buffer.insert(buffer.end(), p.begin(), p.end()); - } - return widen_string(absl::string_view(buffer.data() + offset, buffer.size() - offset)); } -} // namespace + size_t offset = buffer.size(); -native_string_type OSService::concat_and_norm(const std::string& base_dir, const std::string& path) -{ - return concat_and_norm_path(absl::string_view(base_dir.data(), base_dir.size()), - absl::string_view(path.data(), path.size())); + static constexpr absl::string_view LONG_PATH_PREFIX = R"(\\)"; + + if (!absl::StartsWith(base_dir, LONG_PATH_PREFIX)) + { + buffer.push_back('\\'); + buffer.push_back('\\'); + buffer.push_back('?'); + } + else + { + buffer.push_back('\\'); + } + for (absl::string_view p : pieces) + { + buffer.push_back('\\'); + buffer.insert(buffer.end(), p.begin(), p.end()); + } + return widen_string(absl::string_view(buffer.data() + offset, buffer.size() - offset)); } OSService::OSService(const std::string& path)