mirror of
https://github.com/mhx/dwarfs.git
synced 2025-09-17 16:31:27 -04:00
WIP more windows tweaks
This commit is contained in:
parent
fd157eb611
commit
06647decd6
@ -31,6 +31,5 @@ std::string time_with_unit(double sec);
|
|||||||
std::string size_with_unit(size_t size);
|
std::string size_with_unit(size_t size);
|
||||||
size_t parse_size_with_unit(std::string const& str);
|
size_t parse_size_with_unit(std::string const& str);
|
||||||
std::chrono::milliseconds parse_time_with_unit(std::string const& str);
|
std::chrono::milliseconds parse_time_with_unit(std::string const& str);
|
||||||
std::string get_program_path();
|
|
||||||
|
|
||||||
} // namespace dwarfs
|
} // namespace dwarfs
|
||||||
|
@ -35,8 +35,10 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#ifndef _WIN32
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <fmt/format.h>
|
#include <fmt/format.h>
|
||||||
|
|
||||||
@ -109,7 +111,8 @@ class cached_block {
|
|||||||
return last_access_ < tp;
|
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);
|
auto page_size = ::sysconf(_SC_PAGESIZE);
|
||||||
tmp.resize((data_.size() + page_size - 1) / page_size);
|
tmp.resize((data_.size() + page_size - 1) / page_size);
|
||||||
if (::mincore(const_cast<uint8_t*>(data_.data()), data_.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(),
|
return std::any_of(tmp.begin(), tmp.end(),
|
||||||
[](auto i) { return (i & 1) == 0; });
|
[](auto i) { return (i & 1) == 0; });
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,8 +24,6 @@
|
|||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include <sys/types.h>
|
|
||||||
|
|
||||||
#include <folly/gen/Base.h>
|
#include <folly/gen/Base.h>
|
||||||
|
|
||||||
#include "dwarfs/block_compressor.h"
|
#include "dwarfs/block_compressor.h"
|
||||||
|
@ -21,10 +21,11 @@
|
|||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
#include <filesystem>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
|
|
||||||
#include <sys/stat.h>
|
// #include <sys/stat.h>
|
||||||
|
|
||||||
#include <fmt/format.h>
|
#include <fmt/format.h>
|
||||||
|
|
||||||
@ -33,10 +34,13 @@
|
|||||||
|
|
||||||
namespace dwarfs {
|
namespace dwarfs {
|
||||||
|
|
||||||
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
uint16_t constexpr all_perm_bits = 07777;
|
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 };
|
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;
|
break;
|
||||||
|
|
||||||
case oper::SET_BITS:
|
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;
|
perm_or = op_bits;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -190,17 +195,17 @@ chmod_transformer::chmod_transformer(std::string_view spec, uint16_t umask) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 'u':
|
case 'u':
|
||||||
affected |= S_IXUSR;
|
affected |= uint16_t(fs::perms::owner_exec);
|
||||||
setid_bits |= S_ISUID;
|
setid_bits |= uint16_t(fs::perms::set_uid);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'g':
|
case 'g':
|
||||||
affected |= S_IXGRP;
|
affected |= uint16_t(fs::perms::group_exec);
|
||||||
setid_bits |= S_ISGID;
|
setid_bits |= uint16_t(fs::perms::set_gid);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'o':
|
case 'o':
|
||||||
affected |= S_IXOTH;
|
affected |= uint16_t(fs::perms::others_exec);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'a':
|
case 'a':
|
||||||
@ -249,11 +254,11 @@ chmod_transformer::chmod_transformer(std::string_view spec, uint16_t umask) {
|
|||||||
case state::PARSE_PERMS:
|
case state::PARSE_PERMS:
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 'r':
|
case 'r':
|
||||||
perms |= S_IROTH;
|
perms |= uint16_t(fs::perms::others_read);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'w':
|
case 'w':
|
||||||
perms |= S_IWOTH;
|
perms |= uint16_t(fs::perms::others_write);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'X':
|
case 'X':
|
||||||
@ -261,16 +266,16 @@ chmod_transformer::chmod_transformer(std::string_view spec, uint16_t umask) {
|
|||||||
[[fallthrough]];
|
[[fallthrough]];
|
||||||
|
|
||||||
case 'x':
|
case 'x':
|
||||||
perms |= S_IXOTH;
|
perms |= uint16_t(fs::perms::others_exec);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 's':
|
case 's':
|
||||||
// default to S_ISUID unless explicitly specified
|
// default to fs::perms::set_uid unless explicitly specified
|
||||||
hi_bits |= setid_bits ? setid_bits : S_ISUID;
|
hi_bits |= setid_bits ? setid_bits : uint16_t(fs::perms::set_uid);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 't':
|
case 't':
|
||||||
hi_bits |= S_ISVTX;
|
hi_bits |= uint16_t(fs::perms::sticky_bit);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'u':
|
case 'u':
|
||||||
|
@ -28,12 +28,6 @@
|
|||||||
#include <numeric>
|
#include <numeric>
|
||||||
#include <ostream>
|
#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 <boost/algorithm/string.hpp>
|
||||||
|
|
||||||
#include <thrift/lib/cpp2/frozen/FrozenUtil.h>
|
#include <thrift/lib/cpp2/frozen/FrozenUtil.h>
|
||||||
|
@ -32,8 +32,6 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#include <folly/ExceptionString.h>
|
#include <folly/ExceptionString.h>
|
||||||
|
|
||||||
#include <fmt/format.h>
|
#include <fmt/format.h>
|
||||||
|
@ -26,13 +26,19 @@
|
|||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
#ifndef _WIN32
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "dwarfs/terminal.h"
|
#include "dwarfs/terminal.h"
|
||||||
|
|
||||||
namespace dwarfs {
|
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))) {
|
if (&os == &std::cout && !::isatty(::fileno(stdout))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -41,6 +47,7 @@ bool stream_is_fancy_terminal(std::ostream& os) {
|
|||||||
}
|
}
|
||||||
auto term = ::getenv("TERM");
|
auto term = ::getenv("TERM");
|
||||||
return term && term[0] != '\0' && ::strcmp(term, "dumb") != 0;
|
return term && term[0] != '\0' && ::strcmp(term, "dumb") != 0;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
char const* terminal_color(termcolor color) {
|
char const* terminal_color(termcolor color) {
|
||||||
|
@ -25,8 +25,6 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#include <folly/String.h>
|
#include <folly/String.h>
|
||||||
|
|
||||||
#include "dwarfs/error.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");
|
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
|
} // namespace dwarfs
|
||||||
|
Loading…
x
Reference in New Issue
Block a user