From 06647decd6b70306940362546968ccbc2d8896d2 Mon Sep 17 00:00:00 2001 From: Marcus Holland-Moritz Date: Thu, 22 Jun 2023 00:57:26 +0200 Subject: [PATCH] WIP more windows tweaks --- include/dwarfs/util.h | 1 - src/dwarfs/block_cache.cpp | 6 +++++- src/dwarfs/block_compressor.cpp | 2 -- src/dwarfs/chmod_transformer.cpp | 33 ++++++++++++++++++-------------- src/dwarfs/metadata_v2.cpp | 6 ------ src/dwarfs/scanner.cpp | 2 -- src/dwarfs/terminal.cpp | 9 ++++++++- src/dwarfs/util.cpp | 24 ----------------------- 8 files changed, 32 insertions(+), 51 deletions(-) diff --git a/include/dwarfs/util.h b/include/dwarfs/util.h index 1326c5cf..d1d321ff 100644 --- a/include/dwarfs/util.h +++ b/include/dwarfs/util.h @@ -31,6 +31,5 @@ std::string time_with_unit(double sec); std::string size_with_unit(size_t size); size_t parse_size_with_unit(std::string const& str); std::chrono::milliseconds parse_time_with_unit(std::string const& str); -std::string get_program_path(); } // namespace dwarfs diff --git a/src/dwarfs/block_cache.cpp b/src/dwarfs/block_cache.cpp index d8ee4327..d2dc453e 100644 --- a/src/dwarfs/block_cache.cpp +++ b/src/dwarfs/block_cache.cpp @@ -35,8 +35,10 @@ #include #include +#ifndef _WIN32 #include #include +#endif #include @@ -109,7 +111,8 @@ class cached_block { return last_access_ < tp; } - bool any_pages_swapped_out(std::vector& tmp) const { + bool any_pages_swapped_out(std::vector& tmp [[maybe_unused]]) const { +#ifndef _WIN32 auto page_size = ::sysconf(_SC_PAGESIZE); tmp.resize((data_.size() + page_size - 1) / page_size); if (::mincore(const_cast(data_.data()), data_.size(), @@ -118,6 +121,7 @@ class cached_block { return std::any_of(tmp.begin(), tmp.end(), [](auto i) { return (i & 1) == 0; }); } +#endif return false; } diff --git a/src/dwarfs/block_compressor.cpp b/src/dwarfs/block_compressor.cpp index a94570b1..1d450bec 100644 --- a/src/dwarfs/block_compressor.cpp +++ b/src/dwarfs/block_compressor.cpp @@ -24,8 +24,6 @@ #include #include -#include - #include #include "dwarfs/block_compressor.h" diff --git a/src/dwarfs/chmod_transformer.cpp b/src/dwarfs/chmod_transformer.cpp index 8aa7e34a..ea908064 100644 --- a/src/dwarfs/chmod_transformer.cpp +++ b/src/dwarfs/chmod_transformer.cpp @@ -21,10 +21,11 @@ #include #include +#include #include #include -#include +// #include #include @@ -33,10 +34,13 @@ namespace dwarfs { +namespace fs = std::filesystem; + namespace { uint16_t constexpr all_perm_bits = 07777; -uint16_t constexpr all_exec_bits = S_IXUSR | S_IXGRP | S_IXOTH; +uint16_t constexpr all_exec_bits = uint16_t( + fs::perms::owner_exec | fs::perms::group_exec | fs::perms::others_exec); enum class oper { NONE, ADD_BITS, SUB_BITS, SET_BITS, OCT_BITS }; @@ -66,7 +70,8 @@ compute_perm_and_or(oper op, uint16_t hi_bits, uint16_t setid_bits, break; case oper::SET_BITS: - perm_and = all_perm_bits & ~((affected * S_IRWXO) | setid_bits); + perm_and = all_perm_bits & + ~((affected * uint16_t(fs::perms::others_all)) | setid_bits); perm_or = op_bits; break; @@ -190,17 +195,17 @@ chmod_transformer::chmod_transformer(std::string_view spec, uint16_t umask) { break; case 'u': - affected |= S_IXUSR; - setid_bits |= S_ISUID; + affected |= uint16_t(fs::perms::owner_exec); + setid_bits |= uint16_t(fs::perms::set_uid); break; case 'g': - affected |= S_IXGRP; - setid_bits |= S_ISGID; + affected |= uint16_t(fs::perms::group_exec); + setid_bits |= uint16_t(fs::perms::set_gid); break; case 'o': - affected |= S_IXOTH; + affected |= uint16_t(fs::perms::others_exec); break; case 'a': @@ -249,11 +254,11 @@ chmod_transformer::chmod_transformer(std::string_view spec, uint16_t umask) { case state::PARSE_PERMS: switch (c) { case 'r': - perms |= S_IROTH; + perms |= uint16_t(fs::perms::others_read); break; case 'w': - perms |= S_IWOTH; + perms |= uint16_t(fs::perms::others_write); break; case 'X': @@ -261,16 +266,16 @@ chmod_transformer::chmod_transformer(std::string_view spec, uint16_t umask) { [[fallthrough]]; case 'x': - perms |= S_IXOTH; + perms |= uint16_t(fs::perms::others_exec); break; case 's': - // default to S_ISUID unless explicitly specified - hi_bits |= setid_bits ? setid_bits : S_ISUID; + // default to fs::perms::set_uid unless explicitly specified + hi_bits |= setid_bits ? setid_bits : uint16_t(fs::perms::set_uid); break; case 't': - hi_bits |= S_ISVTX; + hi_bits |= uint16_t(fs::perms::sticky_bit); break; case 'u': diff --git a/src/dwarfs/metadata_v2.cpp b/src/dwarfs/metadata_v2.cpp index 5e93131d..6e7ab59a 100644 --- a/src/dwarfs/metadata_v2.cpp +++ b/src/dwarfs/metadata_v2.cpp @@ -28,12 +28,6 @@ #include #include -#include -#include -#include -#include -#include - #include #include diff --git a/src/dwarfs/scanner.cpp b/src/dwarfs/scanner.cpp index 26545113..65a2255c 100644 --- a/src/dwarfs/scanner.cpp +++ b/src/dwarfs/scanner.cpp @@ -32,8 +32,6 @@ #include #include -#include - #include #include diff --git a/src/dwarfs/terminal.cpp b/src/dwarfs/terminal.cpp index bdb8eeb1..2537eaf3 100644 --- a/src/dwarfs/terminal.cpp +++ b/src/dwarfs/terminal.cpp @@ -26,13 +26,19 @@ #include #include +#ifndef _WIN32 #include +#endif #include "dwarfs/terminal.h" namespace dwarfs { -bool stream_is_fancy_terminal(std::ostream& os) { +bool stream_is_fancy_terminal(std::ostream& os [[maybe_unused]]) { +#ifdef _WIN32 + // TODO + return false; +#else if (&os == &std::cout && !::isatty(::fileno(stdout))) { return false; } @@ -41,6 +47,7 @@ bool stream_is_fancy_terminal(std::ostream& os) { } auto term = ::getenv("TERM"); return term && term[0] != '\0' && ::strcmp(term, "dumb") != 0; +#endif } char const* terminal_color(termcolor color) { diff --git a/src/dwarfs/util.cpp b/src/dwarfs/util.cpp index 362eb64b..fd869e21 100644 --- a/src/dwarfs/util.cpp +++ b/src/dwarfs/util.cpp @@ -25,8 +25,6 @@ #include #include -#include - #include #include "dwarfs/error.h" @@ -120,26 +118,4 @@ std::chrono::milliseconds parse_time_with_unit(std::string const& str) { DWARFS_THROW(runtime_error, "unsupported time suffix"); } -std::string get_program_path() { - static const std::array paths = {{ - "/proc/self/exe", - "/proc/curproc/file", - "/proc/self/path/a.out", - }}; - - for (auto cand : paths) { - std::array linkname; - - auto r = ::readlink(cand, linkname.data(), PATH_MAX); - - if (r == -1) { - continue; - } - - return std::string(linkname.data(), r); - } - - return std::string(); -} - } // namespace dwarfs