WIP more windows tweaks

This commit is contained in:
Marcus Holland-Moritz 2023-06-22 00:57:26 +02:00
parent fd157eb611
commit 06647decd6
8 changed files with 32 additions and 51 deletions

View File

@ -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

View File

@ -35,8 +35,10 @@
#include <utility>
#include <vector>
#ifndef _WIN32
#include <sys/mman.h>
#include <unistd.h>
#endif
#include <fmt/format.h>
@ -109,7 +111,8 @@ class cached_block {
return last_access_ < tp;
}
bool any_pages_swapped_out(std::vector<uint8_t>& tmp) const {
bool any_pages_swapped_out(std::vector<uint8_t>& 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<uint8_t*>(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;
}

View File

@ -24,8 +24,6 @@
#include <cstdint>
#include <iostream>
#include <sys/types.h>
#include <folly/gen/Base.h>
#include "dwarfs/block_compressor.h"

View File

@ -21,10 +21,11 @@
#include <cassert>
#include <cstdint>
#include <filesystem>
#include <optional>
#include <tuple>
#include <sys/stat.h>
// #include <sys/stat.h>
#include <fmt/format.h>
@ -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':

View File

@ -28,12 +28,6 @@
#include <numeric>
#include <ostream>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/statvfs.h>
#include <time.h>
#include <unistd.h>
#include <boost/algorithm/string.hpp>
#include <thrift/lib/cpp2/frozen/FrozenUtil.h>

View File

@ -32,8 +32,6 @@
#include <utility>
#include <vector>
#include <unistd.h>
#include <folly/ExceptionString.h>
#include <fmt/format.h>

View File

@ -26,13 +26,19 @@
#include <cstring>
#include <iostream>
#ifndef _WIN32
#include <unistd.h>
#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) {

View File

@ -25,8 +25,6 @@
#include <string>
#include <string_view>
#include <unistd.h>
#include <folly/String.h>
#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<const char*, 3> paths = {{
"/proc/self/exe",
"/proc/curproc/file",
"/proc/self/path/a.out",
}};
for (auto cand : paths) {
std::array<char, PATH_MAX> linkname;
auto r = ::readlink(cand, linkname.data(), PATH_MAX);
if (r == -1) {
continue;
}
return std::string(linkname.data(), r);
}
return std::string();
}
} // namespace dwarfs