add a cmake option to switch between std and boost filesystem

This commit is contained in:
Chunting Gu
2021-05-27 11:15:08 +08:00
parent 39719c4ded
commit df96f969bc
31 changed files with 227 additions and 195 deletions
+4 -7
View File
@@ -3,14 +3,11 @@
#include <iostream>
#include "boost/algorithm/string.hpp"
#include "boost/filesystem/operations.hpp"
#include "json/json.h"
#include "book_json.h"
namespace bfs = boost::filesystem;
BookClient::BookClient(const std::string& url, int timeout)
: url_(url), session_(timeout) {
// Default Content-Type for requests with a body.
@@ -127,7 +124,7 @@ 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 webcc::fs::path& path) {
try {
auto r = session_.Send(WEBCC_GET(url_).
Path("books").Path(id).Path("photo")(),
@@ -147,7 +144,7 @@ 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 webcc::fs::path& path) {
try {
if (!CheckPhoto(path)) {
return false;
@@ -169,12 +166,12 @@ bool BookClient::SetPhoto(const std::string& id, const bfs::path& path) {
}
}
bool BookClient::CheckPhoto(const bfs::path& photo) {
bool BookClient::CheckPhoto(const webcc::fs::path& photo) {
if (photo.empty()) {
return false;
}
if (!bfs::is_regular_file(photo) || !bfs::exists(photo)) {
if (!webcc::fs::is_regular_file(photo) || !webcc::fs::exists(photo)) {
return false;
}
+4 -5
View File
@@ -4,11 +4,10 @@
#include <list>
#include <string>
#include "boost/filesystem/path.hpp"
#include "json/json-forwards.h"
#include "webcc/client_session.h"
#include "webcc/fs.h"
#include "book.h"
@@ -29,13 +28,13 @@ public:
bool Delete(const std::string& id);
// Get photo, save to the given path.
bool GetPhoto(const std::string& id, const boost::filesystem::path& path);
bool GetPhoto(const std::string& id, const webcc::fs::path& path);
// Set photo using the file of the given path.
bool SetPhoto(const std::string& id, const boost::filesystem::path& path);
bool SetPhoto(const std::string& id, const webcc::fs::path& path);
private:
bool CheckPhoto(const boost::filesystem::path& photo);
bool CheckPhoto(const webcc::fs::path& photo);
// Check HTTP response status.
bool CheckStatus(webcc::ResponsePtr response, int expected_status);
+3 -6
View File
@@ -1,13 +1,10 @@
#include <iostream>
#include "boost/filesystem/operations.hpp"
#include "webcc/fs.h"
#include "webcc/logger.h"
#include "book_client.h"
namespace bfs = boost::filesystem;
// -----------------------------------------------------------------------------
void PrintSeparator() {
@@ -39,8 +36,8 @@ 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)) {
webcc::fs::path photo_dir = argv[2];
if (!webcc::fs::is_directory(photo_dir) || !webcc::fs::exists(photo_dir)) {
std::cerr << "Invalid photo dir!" << std::endl;
return 1;
}