switch back to boost::filesystem to avoid the requirement of c++17
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
#include "views.h"
|
||||
|
||||
#include "boost/filesystem/operations.hpp"
|
||||
|
||||
#include "json/json.h"
|
||||
|
||||
#include "webcc/response_builder.h"
|
||||
@@ -8,6 +10,8 @@
|
||||
#include "book_db.h"
|
||||
#include "book_json.h"
|
||||
|
||||
namespace bfs = boost::filesystem;
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
static BookDB g_book_db;
|
||||
@@ -53,7 +57,7 @@ webcc::ResponsePtr BookListView::Post(webcc::RequestPtr request) {
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
BookDetailView::BookDetailView(std::filesystem::path photo_dir)
|
||||
BookDetailView::BookDetailView(bfs::path photo_dir)
|
||||
: photo_dir_(std::move(photo_dir)) {
|
||||
}
|
||||
|
||||
@@ -121,8 +125,8 @@ webcc::ResponsePtr BookDetailView::Delete(webcc::RequestPtr request) {
|
||||
|
||||
// Delete the photo from file system.
|
||||
if (!photo_name.empty()) {
|
||||
std::error_code ec;
|
||||
std::filesystem::remove(photo_dir_ / photo_name, ec);
|
||||
boost::system::error_code ec;
|
||||
bfs::remove(photo_dir_ / photo_name, ec);
|
||||
}
|
||||
|
||||
return webcc::ResponseBuilder{}.OK()();
|
||||
@@ -130,7 +134,7 @@ webcc::ResponsePtr BookDetailView::Delete(webcc::RequestPtr request) {
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
BookPhotoView::BookPhotoView(std::filesystem::path photo_dir)
|
||||
BookPhotoView::BookPhotoView(bfs::path photo_dir)
|
||||
: photo_dir_(std::move(photo_dir)) {
|
||||
}
|
||||
|
||||
@@ -160,8 +164,8 @@ webcc::ResponsePtr BookPhotoView::Get(webcc::RequestPtr request) {
|
||||
return webcc::ResponseBuilder{}.NotFound()();
|
||||
}
|
||||
|
||||
std::filesystem::path photo_path = photo_dir_ / book.photo;
|
||||
if (!std::filesystem::exists(photo_path)) {
|
||||
bfs::path photo_path = photo_dir_ / book.photo;
|
||||
if (!bfs::exists(photo_path)) {
|
||||
return webcc::ResponseBuilder{}.NotFound()();
|
||||
}
|
||||
|
||||
@@ -215,8 +219,8 @@ webcc::ResponsePtr BookPhotoView::Delete(webcc::RequestPtr request) {
|
||||
}
|
||||
|
||||
// Error handling is simplified.
|
||||
std::error_code ec;
|
||||
std::filesystem::remove(photo_dir_ / book.photo, ec);
|
||||
boost::system::error_code ec;
|
||||
bfs::remove(photo_dir_ / book.photo, ec);
|
||||
|
||||
return webcc::ResponseBuilder{}.OK()();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user