Skip to content

Commit

Permalink
seastar: re-introduce compat::filesystem namespace
Browse files Browse the repository at this point in the history
[Reverted in 307335a]

Stop using boost::filesystem altogether and std::experimental::filesystem directly.
Instead, define seastar::compat::filesystem as either std::filesystem, starting in
C++17, or std::experimental::filesystem otherwise.

Changes since c640d8f:

- Base definition on c++ dialect rather than on
  --use-std-optional-variant-stringview
- Consequently, does not modify this switch nor
  the respective STD_OPTIONAL_VARIANT_STRINGVIEW definition

Signed-off-by: Benny Halevy <[email protected]>
Message-Id: <[email protected]>
  • Loading branch information
bhalevy authored and avikivity committed Jan 17, 2019
1 parent 9b8337e commit 79e846e
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 10 deletions.
3 changes: 1 addition & 2 deletions apps/iotune/iotune.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#include <cmath>
#include <sys/vfs.h>
#include <sys/sysmacros.h>
#include <boost/filesystem.hpp>
#include <boost/range/irange.hpp>
#include <boost/program_options.hpp>
#include <boost/iterator/counting_iterator.hpp>
Expand All @@ -52,7 +51,7 @@

using namespace seastar;
using namespace std::chrono_literals;
namespace fs = std::experimental::filesystem;
namespace fs = seastar::compat::filesystem;

logger iotune_logger("iotune");

Expand Down
4 changes: 2 additions & 2 deletions include/seastar/util/read_first_line.hh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include <experimental/filesystem>
#include <seastar/util/std-compat.hh>
#include <seastar/core/sstring.hh>

namespace seastar {

sstring read_first_line(std::experimental::filesystem::path sys_file);
sstring read_first_line(compat::filesystem::path sys_file);

}
12 changes: 12 additions & 0 deletions include/seastar/util/std-compat.hh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@
#include <boost/variant.hpp>
#endif

#if __cplusplus >= 201703L // C++17
#include <filesystem>
#else
#include <experimental/filesystem>
#endif

namespace seastar {

/// \cond internal
Expand Down Expand Up @@ -169,6 +175,12 @@ const U* get_if(const variant<Types...>* v) {

#endif

#if __cplusplus >= 201703L
namespace filesystem = std::filesystem;
#else
namespace filesystem = std::experimental::filesystem;
#endif

using string_view = basic_string_view<char>;

} // namespace compat
Expand Down
6 changes: 2 additions & 4 deletions src/core/reactor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
#include <sys/eventfd.h>
#include <sys/poll.h>
#include <boost/lexical_cast.hpp>
#include <boost/filesystem.hpp>
#include <boost/thread/barrier.hpp>
#include <boost/algorithm/string/classification.hpp>
#include <boost/algorithm/string/split.hpp>
Expand All @@ -67,7 +66,6 @@
#include <boost/range/adaptor/map.hpp>
#include <boost/version.hpp>
#include <atomic>
#include <experimental/filesystem>
#include <dirent.h>
#include <linux/types.h> // for xfs, below
#include <sys/ioctl.h>
Expand Down Expand Up @@ -413,7 +411,7 @@ void task_histogram_add_task(const task& t) {
}

using namespace std::chrono_literals;
namespace fs = std::experimental::filesystem;
namespace fs = seastar::compat::filesystem;

using namespace net;

Expand Down Expand Up @@ -5539,7 +5537,7 @@ void reactor::add_high_priority_task(std::unique_ptr<task>&& t) {
static
bool
virtualized() {
return boost::filesystem::exists("/sys/hypervisor/type");
return fs::exists("/sys/hypervisor/type");
}

std::chrono::nanoseconds
Expand Down
2 changes: 1 addition & 1 deletion src/core/resource.cc
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ allocate_io_queues(hwloc_topology_t& topology, std::vector<cpu> cpus, unsigned n


size_t get_cgroup_memory_limit() {
std::experimental::filesystem::path cgroup_memory = "/sys/fs/cgroup/memory/memory.limit_in_bytes";
compat::filesystem::path cgroup_memory = "/sys/fs/cgroup/memory/memory.limit_in_bytes";

try {
return boost::lexical_cast<size_t>(read_first_line(cgroup_memory));
Expand Down
2 changes: 1 addition & 1 deletion src/util/read_first_line.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace seastar {

sstring read_first_line(std::experimental::filesystem::path sys_file) {
sstring read_first_line(compat::filesystem::path sys_file) {
auto file = file_desc::open(sys_file.string(), O_RDONLY | O_CLOEXEC);
sstring buf;
size_t n = 0;
Expand Down

0 comments on commit 79e846e

Please sign in to comment.