Feature #7450 ยป stdfs.patch
CMakeLists.txt | ||
---|---|---|
OPTION(CONNECTOR_HTTP "Compile in stand-alone httpd connector (libwthttp) ?" ON)
|
||
SET(EXAMPLES_CONNECTOR wthttp CACHE STRING "Connector used for examples")
|
||
SET(WT_CPP17_FILESYSTEM_IMPLEMENTATION "boost" CACHE STRING
|
||
"Implementation for Wt::cpp17::filesystem. Defaults to \"boost\", but can be set to \"std\" for std::filesystem. This is mostly used internally and in the examples.")
|
||
SET_PROPERTY(CACHE WT_CPP17_FILESYSTEM_IMPLEMENTATION PROPERTY STRINGS boost std)
|
||
IF (${WT_CPP17_FILESYSTEM_IMPLEMENTATION} STREQUAL "boost")
|
||
SET(WT_FILESYSTEM_IMPL_BOOST ON)
|
||
ELSEIF(${WT_CPP17_FILESYSTEM_IMPLEMENTATION} STREQUAL "std")
|
||
SET(WT_FILESYSTEM_IMPL_STD ON)
|
||
ELSE()
|
||
MESSAGE(FATAL_ERROR "WT_CPP17_FILESYSTEM_IMPLEMENTATION must be boost or std")
|
||
ENDIF()
|
||
include (CheckSymbolExists)
|
||
find_package(PNG)
|
WConfig.h.in | ||
---|---|---|
#cmakedefine WT_ANY_IS_EXPERIMENTAL_ANY
|
||
#cmakedefine WT_ANY_IS_STD_ANY
|
||
#cmakedefine WT_FILESYSTEM_IMPL_BOOST
|
||
#cmakedefine WT_FILESYSTEM_IMPL_STD
|
||
#cmakedefine WT_ASIO_IS_BOOST_ASIO
|
||
#cmakedefine WT_ASIO_IS_STANDALONE_ASIO
|
||
cmake/WtFindBoost.txt | ||
---|---|---|
SET(Boost_COMPONENTS
|
||
program_options
|
||
filesystem
|
||
thread
|
||
)
|
||
IF(WT_CPP17_FILESYSTEM_IMPLEMENTATION STREQUAL "boost")
|
||
SET(Boost_COMPONENTS
|
||
${Boost_COMPONENTS}
|
||
filesystem)
|
||
ENDIF()
|
||
function(find_boost_system)
|
||
find_package(Boost 1.50 QUIET
|
||
COMPONENTS
|
examples/filetreetable/CMakeLists.txt | ||
---|---|---|
IF(NOT BOOST_FS_LIB)
|
||
MESSAGE(STATUS "** Not building filetreetable example: requires boost_filesystem library.")
|
||
ELSE(NOT BOOST_FS_LIB)
|
||
IF(NOT (WT_CPP17_FILESYSTEM_IMPLEMENTATION STREQUAL "std" OR BOOST_FS_LIB))
|
||
MESSAGE(STATUS "** Not building filetreetable example: requires std::filesystem or boost_filesystem library.")
|
||
ELSE()
|
||
WT_ADD_EXAMPLE(filetreetable.wt
|
||
FileTreeTable.C
|
||
... | ... | |
INCLUDE_DIRECTORIES(${WT_SOURCE_DIR}/src)
|
||
ENDIF(NOT BOOST_FS_LIB)
|
||
ENDIF()
|
||
examples/filetreetable/FileTreeTable.C | ||
---|---|---|
#include <Wt/WText.h>
|
||
#include <Wt/cpp17/filesystem.hpp>
|
||
using namespace Wt;
|
||
FileTreeTable::FileTreeTable(const boost::filesystem::path& path)
|
||
FileTreeTable::FileTreeTable(const cpp17::filesystem::path& path)
|
||
: WTreeTable()
|
||
{
|
||
addColumn("Size", 80);
|
examples/filetreetable/FileTreeTable.h | ||
---|---|---|
#include <Wt/WTreeTable.h>
|
||
#include <boost/filesystem/path.hpp>
|
||
#include <Wt/cpp17/filesystem.hpp>
|
||
/**
|
||
* \defgroup fileexplorer File Explorer example
|
||
... | ... | |
*
|
||
* Create a new FileTreeTable to browse the given path.
|
||
*/
|
||
FileTreeTable(const boost::filesystem::path& path);
|
||
FileTreeTable(const Wt::cpp17::filesystem::path& path);
|
||
};
|
||
/*@}*/
|
examples/filetreetable/FileTreeTableNode.C | ||
---|---|---|
#include "FileTreeTableNode.h"
|
||
#include <boost/filesystem/operations.hpp>
|
||
#include <boost/filesystem/exception.hpp>
|
||
#include <boost/lexical_cast.hpp>
|
||
#include <iostream>
|
||
#include <Wt/WDateTime.h>
|
||
... | ... | |
#include <Wt/WText.h>
|
||
#include <Wt/WAny.h>
|
||
FileTreeTableNode::FileTreeTableNode(const boost::filesystem::path& path)
|
||
#include <Wt/cpp17/filesystem.hpp>
|
||
FileTreeTableNode::FileTreeTableNode(const cpp17::filesystem::path& path)
|
||
#if BOOST_FILESYSTEM_VERSION < 3
|
||
: WTreeTableNode(Wt::widen(path.leaf()), createIcon(path)),
|
||
#else
|
||
... | ... | |
{
|
||
label()->setTextFormat(TextFormat::Plain);
|
||
if (boost::filesystem::exists(path)) {
|
||
if (!boost::filesystem::is_directory(path)) {
|
||
int fsize = (int)boost::filesystem::file_size(path);
|
||
if (cpp17::filesystem::exists(path)) {
|
||
if (!cpp17::filesystem::is_directory(path)) {
|
||
int fsize = (int)cpp17::filesystem::file_size(path);
|
||
setColumnWidget(1, cpp14::make_unique<WText>(asString(fsize)));
|
||
columnWidget(1)->setStyleClass("fsize");
|
||
} else
|
||
setSelectable(false);
|
||
std::time_t t = boost::filesystem::last_write_time(path);
|
||
std::time_t t = cpp17::filesystem::last_write_time(path);
|
||
Wt::WDateTime dateTime = Wt::WDateTime::fromTime_t(t);
|
||
Wt::WLocalDateTime localDateTime = dateTime.toLocalTime();
|
||
Wt::WString dateTimeStr = localDateTime.toString(Wt::utf8("MMM dd yyyy"));
|
||
... | ... | |
}
|
||
}
|
||
std::unique_ptr<WIconPair> FileTreeTableNode::createIcon(const boost::filesystem::path& path)
|
||
std::unique_ptr<WIconPair> FileTreeTableNode::createIcon(const cpp17::filesystem::path& path)
|
||
{
|
||
if (boost::filesystem::exists(path)
|
||
&& boost::filesystem::is_directory(path))
|
||
if (cpp17::filesystem::exists(path)
|
||
&& cpp17::filesystem::is_directory(path))
|
||
return cpp14::make_unique<WIconPair>("icons/yellow-folder-closed.png",
|
||
"icons/yellow-folder-open.png", false);
|
||
else
|
||
... | ... | |
void FileTreeTableNode::populate()
|
||
{
|
||
if (boost::filesystem::is_directory(path_)) {
|
||
std::set<boost::filesystem::path> paths;
|
||
boost::filesystem::directory_iterator end_itr;
|
||
if (cpp17::filesystem::is_directory(path_)) {
|
||
std::set<cpp17::filesystem::path> paths;
|
||
cpp17::filesystem::directory_iterator end_itr;
|
||
for (boost::filesystem::directory_iterator i(path_); i != end_itr; ++i)
|
||
for (cpp17::filesystem::directory_iterator i(path_); i != end_itr; ++i)
|
||
try {
|
||
paths.insert(*i);
|
||
} catch (boost::filesystem::filesystem_error& e) {
|
||
} catch (cpp17::filesystem::filesystem_error& e) {
|
||
std::cerr << e.what() << std::endl;
|
||
}
|
||
for (std::set<boost::filesystem::path>::iterator i = paths.begin();
|
||
for (std::set<cpp17::filesystem::path>::iterator i = paths.begin();
|
||
i != paths.end(); ++i)
|
||
try {
|
||
addChildNode(cpp14::make_unique<FileTreeTableNode>(*i));
|
||
} catch (boost::filesystem::filesystem_error& e) {
|
||
} catch (cpp17::filesystem::filesystem_error& e) {
|
||
std::cerr << e.what() << std::endl;
|
||
}
|
||
}
|
||
... | ... | |
bool FileTreeTableNode::expandable()
|
||
{
|
||
if (!populated()) {
|
||
return boost::filesystem::is_directory(path_);
|
||
return cpp17::filesystem::is_directory(path_);
|
||
} else
|
||
return WTreeTableNode::expandable();
|
||
}
|
examples/filetreetable/FileTreeTableNode.h | ||
---|---|---|
#include <Wt/WTreeTableNode.h>
|
||
#include <boost/filesystem/path.hpp>
|
||
#include <Wt/cpp17/filesystem.hpp>
|
||
using namespace Wt;
|
||
... | ... | |
public:
|
||
/*! \brief Construct a new node for the given file.
|
||
*/
|
||
FileTreeTableNode(const boost::filesystem::path& path);
|
||
FileTreeTableNode(const cpp17::filesystem::path& path);
|
||
private:
|
||
//! The path.
|
||
boost::filesystem::path path_;
|
||
cpp17::filesystem::path path_;
|
||
//! Reimplements WTreeNode::populate to read files within a directory.
|
||
virtual void populate() override;
|
||
... | ... | |
virtual bool expandable() override;
|
||
//! Create the iconpair for representing the path.
|
||
static std::unique_ptr<WIconPair> createIcon(const boost::filesystem::path& path);
|
||
static std::unique_ptr<WIconPair> createIcon(const cpp17::filesystem::path& path);
|
||
};
|
||
/*@}*/
|
examples/gitmodel/CMakeLists.txt | ||
---|---|---|
IF(NOT WIN32)
|
||
IF(BOOST_FS_LIB)
|
||
IF(WT_CPP17_FILESYSTEM_IMPLEMENTATION STREQUAL "std" OR BOOST_FS_LIB)
|
||
WT_ADD_EXAMPLE(gitview.wt
|
||
Git.C
|
||
GitModel.C
|
||
... | ... | |
ADD_DEPENDENCIES(gitview.wt wt ${EXAMPLES_CONNECTOR})
|
||
ELSE(BOOST_FS_LIB)
|
||
ELSE()
|
||
MESSAGE(STATUS "** Not building gitmodel example: requires boost_filesystem library.")
|
||
MESSAGE(STATUS "** Not building gitmodel example: requires std::filesystem or boost_filesystem library.")
|
||
ENDIF(BOOST_FS_LIB)
|
||
ENDIF()
|
||
ELSE(NOT WIN32)
|
||
examples/wt-homepage/CMakeLists.txt | ||
---|---|---|
IF(BOOST_FS_LIB)
|
||
IF(WT_CPP17_FILESYSTEM_IMPLEMENTATION STREQUAL "std" OR BOOST_FS_LIB)
|
||
INCLUDE(CheckFunctionExists)
|
||
... | ... | |
../blog
|
||
)
|
||
ELSE(BOOST_FS_LIB)
|
||
ELSE()
|
||
|
||
MESSAGE(STATUS "** Not building wt-homepage example: requires boost_filesystem library.")
|
||
MESSAGE(STATUS "** Not building wt-homepage example: requires std::filesystem or boost_filesystem library.")
|
||
ENDIF(BOOST_FS_LIB)
|
||
ENDIF()
|
examples/wt-homepage/ExampleSourceViewer.C | ||
---|---|---|
#include <Wt/WVBoxLayout.h>
|
||
#include <Wt/WViewWidget.h>
|
||
#include <boost/filesystem/operations.hpp>
|
||
#include <boost/filesystem/exception.hpp>
|
||
#include <boost/filesystem/convenience.hpp>
|
||
#include <boost/algorithm/string.hpp>
|
||
#include <Wt/cpp17/filesystem.hpp>
|
||
#include "ExampleSourceViewer.h"
|
||
#include "FileItem.h"
|
||
namespace fs = boost::filesystem;
|
||
namespace fs = cpp17::filesystem;
|
||
// Same as p.filename() in latest boost::filesystem
|
||
static std::string filename(const fs::path& p)
|
||
{
|
||
#if BOOST_FILESYSTEM_VERSION < 3
|
||
#if defined(BOOST_FILESYSTEM_VERISON) && BOOST_FILESYSTEM_VERSION < 3
|
||
return p.empty() ? std::string() : *--p.end();
|
||
#else
|
||
return p.empty() ? std::string() : (*--p.end()).string();
|
examples/wt-homepage/ExampleSourceViewer.h | ||
---|---|---|
#include <Wt/WTreeView.h>
|
||
#include <Wt/WStandardItemModel.h>
|
||
#include <Wt/cpp17/filesystem.hpp>
|
||
#include "FileItem.h"
|
||
#include "SourceView.h"
|
||
... | ... | |
std::shared_ptr<WStandardItemModel> model_;
|
||
void cppTraverseDir(WStandardItem* parent,
|
||
const boost::filesystem::path& path);
|
||
const cpp17::filesystem::path& path);
|
||
void javaTraverseDir(WStandardItem* parent,
|
||
const boost::filesystem::path& path);
|
||
const cpp17::filesystem::path& path);
|
||
void javaTraversePackages(WStandardItem *parent,
|
||
const boost::filesystem::path& srcPath,
|
||
const cpp17::filesystem::path& srcPath,
|
||
const std::string packageName);
|
||
/*! \brief Displayed the currently selected file.
|
examples/wt-homepage/FileItem.h | ||
---|---|---|
#include "Wt/WStandardItemModel.h"
|
||
#include "Wt/WString.h"
|
||
#include <boost/filesystem/operations.hpp>
|
||
#include <boost/filesystem/exception.hpp>
|
||
using namespace Wt;
|
||
/*! \class FileItem
|
examples/wt-homepage/SourceView.C | ||
---|---|---|
#include <stdlib.h>
|
||
#include <boost/algorithm/string.hpp>
|
||
#include <boost/filesystem/operations.hpp>
|
||
#include <boost/filesystem/convenience.hpp>
|
||
#include <Wt/WApplication.h>
|
||
#include <Wt/WText.h>
|
||
#include <Wt/WImage.h>
|
||
#include <Wt/cpp17/filesystem.hpp>
|
||
// TODO(Roel): eliminate this boost algorithm string
|
||
#include <boost/algorithm/string.hpp>
|
||
using namespace Wt;
|
||
namespace fs = boost::filesystem;
|
||
namespace fs = cpp17::filesystem;
|
||
SourceView::SourceView(ItemDataRole fileNameRole,
|
||
ItemDataRole contentRole,
|
src/Wt/cpp17/filesystem.hpp | ||
---|---|---|
// This may look like C code, but it's really -*- C++ -*-
|
||
/*
|
||
* Copyright (C) 2020 Emweb bv, Herent, Belgium.
|
||
*
|
||
* See the LICENSE file for terms of use.
|
||
*/
|
||
#ifndef WT_CPP17_FILESYSTEM_HPP
|
||
#define WT_CPP17_FILESYSTEM_HPP
|
||
#include <Wt/WConfig.h>
|
||
#if defined(WT_FILESYSTEM_IMPL_BOOST)
|
||
#include <boost/filesystem.hpp>
|
||
namespace Wt {
|
||
namespace cpp17 {
|
||
namespace filesystem = boost::filesystem;
|
||
}
|
||
}
|
||
#elif defined(WT_FILESYSTEM_IMPL_STD)
|
||
#include <filesystem>
|
||
namespace Wt {
|
||
namespace cpp17 {
|
||
namespace filesystem = std::filesystem;
|
||
}
|
||
}
|
||
#endif
|
||
#endif // WT_CPP17_FILESYSTEM_HPP
|
src/web/FileUtils.C | ||
---|---|---|
#include "web/FileUtils.h"
|
||
#ifndef WT_HAVE_POSIX_FILEIO
|
||
#include <boost/filesystem/operations.hpp>
|
||
#include "Wt/cpp17/filesystem.hpp"
|
||
#else //WT_HAVE_POSIX_FILEIO
|
||
#include <sys/types.h>
|
||
#include <sys/stat.h>
|
||
... | ... | |
#include <windows.h>
|
||
#endif // WIN32
|
||
#ifndef WT_WIN32
|
||
#include <unistd.h>
|
||
#endif // WT_WIN32
|
||
#include <fstream>
|
||
namespace Wt {
|
||
... | ... | |
unsigned long long size(const std::string &file)
|
||
{
|
||
#ifndef WT_HAVE_POSIX_FILEIO
|
||
return (unsigned long long) boost::filesystem::file_size(file);
|
||
return (unsigned long long) Wt::cpp17::filesystem::file_size(file);
|
||
#else //WT_HAVE_POSIX_FILEIO
|
||
struct stat sb;
|
||
if (stat(file.c_str(), &sb) == -1) {
|
||
... | ... | |
time_t lastWriteTime(const std::string &file)
|
||
{
|
||
#ifndef WT_HAVE_POSIX_FILEIO
|
||
return (unsigned long long)boost::filesystem::last_write_time(file);
|
||
#ifdef WT_FILESYSTEM_IMPL_STD
|
||
// TODO(Roel): can't convert last_write_time to time_t with GCC?
|
||
auto ftime = Wt::cpp17::filesystem::last_write_time(file);
|
||
auto systime = decltype(ftime)::clock::to_sys(ftime);
|
||
return decltype(ftime)::clock::to_time_t(ftime);
|
||
#else // !WT_FILESYSTEM_IMPL_STD
|
||
return (unsigned long long)Wt::cpp17::filesystem::last_write_time(file);
|
||
#endif // WT_FILESYSTEM_IMPL_STD
|
||
#else //WT_HAVE_POSIX_FILEIO
|
||
struct stat sb;
|
||
if (stat(file.c_str(), &sb) == -1) {
|
||
... | ... | |
bool exists(const std::string &file)
|
||
{
|
||
#ifndef WT_HAVE_POSIX_FILEIO
|
||
boost::filesystem::path path(file);
|
||
return boost::filesystem::exists(path);
|
||
Wt::cpp17::filesystem::path path(file);
|
||
return Wt::cpp17::filesystem::exists(path);
|
||
#else //WT_HAVE_POSIX_FILEIO
|
||
struct stat sb;
|
||
return stat(file.c_str(), &sb) != -1;
|
||
... | ... | |
bool isDirectory(const std::string &file)
|
||
{
|
||
#ifndef WT_HAVE_POSIX_FILEIO
|
||
boost::filesystem::path path(file);
|
||
return boost::filesystem::is_directory(path);
|
||
Wt::cpp17::filesystem::path path(file);
|
||
return Wt::cpp17::filesystem::is_directory(path);
|
||
#else //WT_HAVE_POSIX_FILEIO
|
||
struct stat sb;
|
||
stat(file.c_str(), &sb);
|
||
... | ... | |
std::vector<std::string> &files)
|
||
{
|
||
#ifndef WT_HAVE_POSIX_FILEIO
|
||
boost::filesystem::path path(directory);
|
||
boost::filesystem::directory_iterator end_itr;
|
||
Wt::cpp17::filesystem::path path(directory);
|
||
Wt::cpp17::filesystem::directory_iterator end_itr;
|
||
if (!boost::filesystem::is_directory(path)) {
|
||
if (!Wt::cpp17::filesystem::is_directory(path)) {
|
||
std::string error
|
||
= "listFiles: \"" + directory + "\" is not a directory";
|
||
LOG_ERROR(error);
|
||
throw WException(error);
|
||
}
|
||
|
||
for (boost::filesystem::directory_iterator i(path); i != end_itr; ++i) {
|
||
for (Wt::cpp17::filesystem::directory_iterator i(path); i != end_itr; ++i) {
|
||
std::string f = (*i).path().string();
|
||
files.push_back(f);
|
||
}
|
src/web/WebController.C | ||
---|---|---|
#include <magick/api.h>
|
||
#endif
|
||
#ifndef WT_HAVE_POSIX_FILEIO
|
||
#if !defined(WT_HAVE_POSIX_FILEIO) && defined(WT_FILESYSTEM_IMPL_BOOST)
|
||
// boost bug workaround: see WebController constructor
|
||
#include <boost/filesystem.hpp>
|
||
#endif
|
||
... | ... | |
InitializeMagick(0);
|
||
#endif
|
||
#ifndef WT_HAVE_POSIX_FILEIO
|
||
#if !defined(WT_HAVE_POSIX_FILEIO) && defined(WT_FILESYSTEM_IMPL_BOOST)
|
||
// attempted workaround for:
|
||
// https://svn.boost.org/trac/boost/ticket/6320
|
||
// https://svn.boost.org/trac/boost/ticket/4889
|