replace boost filesystem with std filesystem; upgrade gtest and find it using cmake.
This commit is contained in:
@@ -3,7 +3,6 @@
|
||||
#include <iostream>
|
||||
|
||||
#include "boost/algorithm/string/predicate.hpp"
|
||||
#include "boost/filesystem/operations.hpp"
|
||||
#include "json/json.h"
|
||||
|
||||
#include "book_json.h"
|
||||
@@ -125,7 +124,8 @@ bool BookClient::Delete(const std::string& id) {
|
||||
}
|
||||
}
|
||||
|
||||
bool BookClient::GetPhoto(const std::string& id, const bfs::path& path) {
|
||||
bool BookClient::GetPhoto(const std::string& id,
|
||||
const std::filesystem::path& path) {
|
||||
try {
|
||||
auto r = session_.Send(WEBCC_GET(url_).
|
||||
Path("books").Path(id).Path("photo")(),
|
||||
@@ -145,7 +145,8 @@ bool BookClient::GetPhoto(const std::string& id, const bfs::path& path) {
|
||||
}
|
||||
}
|
||||
|
||||
bool BookClient::SetPhoto(const std::string& id, const bfs::path& path) {
|
||||
bool BookClient::SetPhoto(const std::string& id,
|
||||
const std::filesystem::path& path) {
|
||||
try {
|
||||
if (!CheckPhoto(path)) {
|
||||
return false;
|
||||
@@ -167,12 +168,13 @@ bool BookClient::SetPhoto(const std::string& id, const bfs::path& path) {
|
||||
}
|
||||
}
|
||||
|
||||
bool BookClient::CheckPhoto(const bfs::path& photo) {
|
||||
bool BookClient::CheckPhoto(const std::filesystem::path& photo) {
|
||||
if (photo.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!bfs::is_regular_file(photo) || !bfs::exists(photo)) {
|
||||
if (!std::filesystem::is_regular_file(photo) ||
|
||||
!std::filesystem::exists(photo)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#ifndef BOOK_CLIENT_H_
|
||||
#define BOOK_CLIENT_H_
|
||||
|
||||
#include <filesystem>
|
||||
#include <list>
|
||||
#include <string>
|
||||
|
||||
@@ -11,8 +12,6 @@
|
||||
|
||||
#include "book.h"
|
||||
|
||||
namespace bfs = boost::filesystem;
|
||||
|
||||
class BookClient {
|
||||
public:
|
||||
explicit BookClient(const std::string& url, int timeout = 0);
|
||||
@@ -30,13 +29,13 @@ public:
|
||||
bool Delete(const std::string& id);
|
||||
|
||||
// Get photo, save to the given path.
|
||||
bool GetPhoto(const std::string& id, const bfs::path& path);
|
||||
bool GetPhoto(const std::string& id, const std::filesystem::path& path);
|
||||
|
||||
// Set photo using the file of the given path.
|
||||
bool SetPhoto(const std::string& id, const bfs::path& path);
|
||||
bool SetPhoto(const std::string& id, const std::filesystem::path& path);
|
||||
|
||||
private:
|
||||
bool CheckPhoto(const bfs::path& photo);
|
||||
bool CheckPhoto(const std::filesystem::path& photo);
|
||||
|
||||
// Check HTTP response status.
|
||||
bool CheckStatus(webcc::ResponsePtr response, int expected_status);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include <filesystem>
|
||||
#include <iostream>
|
||||
|
||||
#include "boost/filesystem/operations.hpp"
|
||||
#include "webcc/logger.h"
|
||||
|
||||
#include "book_client.h"
|
||||
@@ -45,8 +45,9 @@ int main(int argc, char* argv[]) {
|
||||
|
||||
std::string url = argv[1];
|
||||
|
||||
bfs::path photo_dir = argv[2];
|
||||
if (!bfs::is_directory(photo_dir) || !bfs::exists(photo_dir)) {
|
||||
std::filesystem::path photo_dir = argv[2];
|
||||
if (!std::filesystem::is_directory(photo_dir) ||
|
||||
!std::filesystem::exists(photo_dir)) {
|
||||
std::cerr << "Invalid photo dir!" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#include <filesystem>
|
||||
#include <iostream>
|
||||
|
||||
#include "boost/filesystem/operations.hpp"
|
||||
|
||||
#include "webcc/logger.h"
|
||||
#include "webcc/server.h"
|
||||
|
||||
@@ -28,16 +27,17 @@ int main(int argc, char* argv[]) {
|
||||
|
||||
std::uint16_t port = static_cast<std::uint16_t>(std::atoi(argv[1]));
|
||||
|
||||
bfs::path upload_dir = argv[2];
|
||||
if (!bfs::is_directory(upload_dir) || !bfs::exists(upload_dir)) {
|
||||
std::filesystem::path upload_dir = argv[2];
|
||||
if (!std::filesystem::is_directory(upload_dir) ||
|
||||
!std::filesystem::exists(upload_dir)) {
|
||||
std::cerr << "Invalid upload dir!" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Add a sub-dir for book photos.
|
||||
bfs::path photo_dir = upload_dir / "books";
|
||||
if (!bfs::exists(photo_dir)) {
|
||||
bfs::create_directory(photo_dir);
|
||||
std::filesystem::path photo_dir = upload_dir / "books";
|
||||
if (!std::filesystem::exists(photo_dir)) {
|
||||
std::filesystem::create_directory(photo_dir);
|
||||
}
|
||||
|
||||
std::cout << "Book photos will be saved to: " << photo_dir << std::endl;
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
#include "json/json.h"
|
||||
|
||||
#include "boost/filesystem/operations.hpp"
|
||||
#include "webcc/response_builder.h"
|
||||
|
||||
#include "book.h"
|
||||
@@ -54,7 +53,7 @@ webcc::ResponsePtr BookListView::Post(webcc::RequestPtr request) {
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
BookDetailView::BookDetailView(bfs::path photo_dir)
|
||||
BookDetailView::BookDetailView(std::filesystem::path photo_dir)
|
||||
: photo_dir_(std::move(photo_dir)) {
|
||||
}
|
||||
|
||||
@@ -122,8 +121,8 @@ webcc::ResponsePtr BookDetailView::Delete(webcc::RequestPtr request) {
|
||||
|
||||
// Delete the photo from file system.
|
||||
if (!photo_name.empty()) {
|
||||
boost::system::error_code ec;
|
||||
bfs::remove(photo_dir_ / photo_name, ec);
|
||||
std::error_code ec;
|
||||
std::filesystem::remove(photo_dir_ / photo_name, ec);
|
||||
}
|
||||
|
||||
return webcc::ResponseBuilder{}.OK()();
|
||||
@@ -131,7 +130,7 @@ webcc::ResponsePtr BookDetailView::Delete(webcc::RequestPtr request) {
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
BookPhotoView::BookPhotoView(bfs::path photo_dir)
|
||||
BookPhotoView::BookPhotoView(std::filesystem::path photo_dir)
|
||||
: photo_dir_(std::move(photo_dir)) {
|
||||
}
|
||||
|
||||
@@ -161,8 +160,8 @@ webcc::ResponsePtr BookPhotoView::Get(webcc::RequestPtr request) {
|
||||
return webcc::ResponseBuilder{}.NotFound()();
|
||||
}
|
||||
|
||||
bfs::path photo_path = photo_dir_ / book.photo;
|
||||
if (!bfs::exists(photo_path)) {
|
||||
std::filesystem::path photo_path = photo_dir_ / book.photo;
|
||||
if (!std::filesystem::exists(photo_path)) {
|
||||
return webcc::ResponseBuilder{}.NotFound()();
|
||||
}
|
||||
|
||||
@@ -216,8 +215,8 @@ webcc::ResponsePtr BookPhotoView::Delete(webcc::RequestPtr request) {
|
||||
}
|
||||
|
||||
// Error handling is simplified.
|
||||
boost::system::error_code ec;
|
||||
bfs::remove(photo_dir_ / book.photo, ec);
|
||||
std::error_code ec;
|
||||
std::filesystem::remove(photo_dir_ / book.photo, ec);
|
||||
|
||||
return webcc::ResponseBuilder{}.OK()();
|
||||
}
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
#ifndef VIEWS_H_
|
||||
#define VIEWS_H_
|
||||
|
||||
#include <filesystem>
|
||||
|
||||
#include "webcc/view.h"
|
||||
|
||||
#include "boost/filesystem/path.hpp"
|
||||
|
||||
namespace bfs = boost::filesystem;
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// URL: /books
|
||||
@@ -27,7 +25,7 @@ private:
|
||||
// URL: /books/{id}
|
||||
class BookDetailView : public webcc::View {
|
||||
public:
|
||||
explicit BookDetailView(bfs::path photo_dir);
|
||||
explicit BookDetailView(std::filesystem::path photo_dir);
|
||||
|
||||
webcc::ResponsePtr Handle(webcc::RequestPtr request) override;
|
||||
|
||||
@@ -42,7 +40,7 @@ private:
|
||||
webcc::ResponsePtr Delete(webcc::RequestPtr request);
|
||||
|
||||
private:
|
||||
bfs::path photo_dir_;
|
||||
std::filesystem::path photo_dir_;
|
||||
};
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
@@ -50,7 +48,7 @@ private:
|
||||
// URL: /books/{id}/photo
|
||||
class BookPhotoView : public webcc::View {
|
||||
public:
|
||||
explicit BookPhotoView(bfs::path photo_dir);
|
||||
explicit BookPhotoView(std::filesystem::path photo_dir);
|
||||
|
||||
webcc::ResponsePtr Handle(webcc::RequestPtr request) override;
|
||||
|
||||
@@ -70,7 +68,7 @@ private:
|
||||
webcc::ResponsePtr Delete(webcc::RequestPtr request);
|
||||
|
||||
private:
|
||||
bfs::path photo_dir_;
|
||||
std::filesystem::path photo_dir_;
|
||||
};
|
||||
|
||||
#endif // VIEWS_H_
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
// A client posting multipart form data.
|
||||
|
||||
#include <filesystem>
|
||||
#include <iostream>
|
||||
|
||||
#include "boost/filesystem.hpp"
|
||||
|
||||
#include "webcc/client_session.h"
|
||||
#include "webcc/logger.h"
|
||||
|
||||
namespace sfs = std::filesystem;
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
if (argc < 2) {
|
||||
std::cout << "usage: form_client <upload_dir> [url]" << std::endl;
|
||||
@@ -22,7 +23,7 @@ int main(int argc, char* argv[]) {
|
||||
|
||||
WEBCC_LOG_INIT("", webcc::LOG_CONSOLE);
|
||||
|
||||
const webcc::Path upload_dir(argv[1]);
|
||||
const sfs::path upload_dir(argv[1]);
|
||||
|
||||
std::string url;
|
||||
if (argc == 3) {
|
||||
@@ -31,9 +32,7 @@ int main(int argc, char* argv[]) {
|
||||
url = "http://httpbin.org/post";
|
||||
}
|
||||
|
||||
namespace bfs = boost::filesystem;
|
||||
|
||||
if (!bfs::is_directory(upload_dir) || !bfs::exists(upload_dir)) {
|
||||
if (!sfs::is_directory(upload_dir) || !sfs::exists(upload_dir)) {
|
||||
std::cerr << "Invalid upload dir!" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user